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. Required fields are marked *

You May Also Like…

Toggen builds a new website

So I have built and hosted a new website for Roger Clark Pest Management they are a family owned and operated Pest...


Just downloaded WizTree (not a sponsor) from It seems to do what it says on the tin which is...

Scam call from “Telstra”

Just had a call from a man with a sub-continental accent from caller ID 0734946596 Told me there was problem with my...