Struct is 652 Bytes Fwrite writes 656 Bytes

Written by James McDonald

July 13, 2016

I am not a programmer but I had the need to write a C struct to disk

When I then tried to write another of the same files to try and work-a-round a problem with the system they are used on I got a slightly large (by 4 bytes) file

I was compiling the C program with my MacBook using Xcode version of gcc.

The fix for the extra 4 bytes was to add -fpack-struct to the gcc command line. Which stopped some sort of forced alignment to a 4 byte boundary (I think).

gcc  -fpack-struct capture.c -o capture



Submit a Comment

Your email address will not be published.

You May Also Like…


Zebra Printer Language The above website has a page where you can enter ZPL and it...

PHP Iterators

Just came across a Youtube talk "Iterators in PHP" by Jake Smith published in 2014 that steps through the many...