Gist of the Day: C Structs from Binary Files Using Perl

Hi, did ya miss me? I’m blogging from O’Hare today, it’s going to be a busy week for me with lots of air travel. That won’t stop me from polluting the Internet with yet another blog post though, don’t you worry!
One of the things that we sometimes encounter is a binary file created by some C program writing a struct straight to disk. If we want to get any of that data we will need to parse this file, and read that struct. It’s a little tricky, and you kinda have to know a little bit about either the system on which he program was run, or the intentional decisions made by the program about how the file was written. The most important thing you need to know is the endianness of the binary data. Continue reading “Gist of the Day: C Structs from Binary Files Using Perl”

Gist of the Day: Some convenience macros for use with Perl C internals

I feel awful. Like, really awful. The baby is sick, my partner is sick, I am sick. You still want something neat though, so I’m going to show you something very simple that I’ve used for a while.
As I’m sure you noticed in yesterday’s Inline::C demo, Perl guts and C API are pretty noisy with a lot of boiler-plate. For this reason, when I first started playing with Perl guts and API, I created a header file just to make things a little simpler. Nothing here is terribly complicated, and they’re all just simple convenience macros, but sometimes that type of macro saves you oodles of time. Continue reading “Gist of the Day: Some convenience macros for use with Perl C internals”

Gist of the Day: Inline::C in Perl

I like Perl and I like C (most of the time), and sometimes I like to mix the two. The two main reasons I might want to mix the two is for performance, or because something is written in C which I would like to use from Perl. I’ve only really ever used C from Perl, I’ve never used Perl from C.┬áToday’s demonstration is how to implement a simple binary search algorithm in C, but using Perl internals, and calling the algorithm from Perl. Continue reading “Gist of the Day: Inline::C in Perl”

Gist of the Day: Automated Testing With CUnit

It’s no secret that I love automated testing. I have done automated testing in Perl, C, Java, JavaScript, C++, Python, Objective-C, and PHP. I have yet to find an automated testing framework I didn’t like. C is a unique case since it requires a little more cleverness to perform some of the normal control techniques that you can do with other frameworks.
Continue reading “Gist of the Day: Automated Testing With CUnit”