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

 

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.

You May Also Like…

List local disks

GET-CimInstance -query "SELECT * from Win32_DiskDrive" DeviceID Caption Partitions Size Model -------- -------...

Create ISO using Powershell

Usage New-IsoFile -NewIsoFilePath C:\tmp\Hyper-V.iso-sources -ImageName Hyper-V -SourceFilePath 'C:\tmp\Hyper-V'...