Themain problem I see is that your code is not binary compatible with standard library (it is usually not compiled with structs packed), so calls (with transfering structs) to it may fail (as they actually do).
It is recommended not to pack all structs with this switch, but if you need packing structure, pack only those you need. I also read that recompiling libstd and/or libs you use with the same fpack-struct could help, but that is a risky option anyway.
By default, the compiler (Intel) would add buffers after b and c, so I could either use the #pragma pack pre-processor command or add -fpack-struct to the compiler flags. Since I have several similar structures in the program, I would like to use -fpack-struct. Other than slowing down my IO some, are there any drawbacks to using the flag instead of the pre-processor command?
The #pragma is part of the source code and helps to document the actual structure's layout. If it were in a Makefile or compiler option external, it is far from obvious by reading the code what the layout is.
There is not in this case. But you have to keep in mind that both those options are compiler-specific. As far as I am aware gcc also supports -fpack-struct, but I have never seen that pragma in gcc code. clang has not documented -fpack-struct. You could now start listing a lot of different compilers and how their mechanisms for packing work.
This option generates traps for signed overflow on addition, subtraction,multiplication operations.The options -ftrapv and -fwrapv override each other, so using-ftrapv -fwrapv on the command-line results in-fwrapv being effective. Note that only active options override, sousing -ftrapv -fwrapv -fno-wrapv on the command-lineresults in -ftrapv being effective.
This option instructs the compiler to assume that signed arithmeticoverflow of addition, subtraction and multiplication wraps aroundusing twos-complement representation. This flag enables some optimizationsand disables others.The options -ftrapv and -fwrapv override each other, so using-ftrapv -fwrapv on the command-line results in-fwrapv being effective. Note that only active options override, sousing -ftrapv -fwrapv -fno-wrapv on the command-lineresults in -ftrapv being effective.
This option instructs the compiler to assume that pointer arithmeticoverflow on addition and subtraction wraps around using twos-complementrepresentation. This flag disables some optimizations which assumepointer overflow is invalid.
Generate code that allows trapping instructions to throw exceptions.Note that this requires platform-specific runtime support that doesnot exist everywhere. Moreover, it only allows trappinginstructions to throw exceptions, i.e. memory references or floating-pointinstructions. It does not allow exceptions to be thrown fromarbitrary signal handlers such as SIGALRM. This enables-fexceptions.
Similar to -fexceptions, except that it just generates any neededstatic data, but does not affect the generated code in any other way.You normally do not need to enable this option; instead, a language processorthat needs this handling enables it on your behalf.
Generate unwind table in DWARF format, if supported by target machine. Thetable is exact at each instruction boundary, so it can be used for stackunwinding from asynchronous events (such as debugger or garbage collector).
On systems with recent GNU assembler and C library, the C++ compileruses the STB_GNU_UNIQUE binding to make sure that definitionsof template static data members and static local variables in inlinefunctions are unique even in the presence of RTLD_LOCAL; thisis necessary to avoid problems with a library used by two differentRTLD_LOCAL plugins depending on a definition in one of them andtherefore disagreeing with the other one about the binding of thesymbol. But this causes dlclose to be ignored for affectedDSOs; if your program relies on reinitialization of a DSO viadlclose and dlopen, you can use-fno-gnu-unique.
Warning: code compiled with the -fpcc-struct-returnswitch is not binary compatible with code compiled with the-freg-struct-return switch.Use it to conform to a non-default application binary interface.
If you specify neither -fpcc-struct-return nor-freg-struct-return, GCC defaults to whichever convention isstandard for the target. If there is no standard convention, GCCdefaults to -fpcc-struct-return, except on targets where GCC isthe principal compiler. In those cases, we can choose the standard, andwe chose the more efficient register return alternative.
Warning: code compiled with the -freg-struct-returnswitch is not binary compatible with code compiled with the-fpcc-struct-return switch.Use it to conform to a non-default application binary interface.
Allocate to an enum type only as many bytes as it needs for thedeclared range of possible values. Specifically, the enum typeis equivalent to the smallest integer type that has enough room.This option has no effect for an enumeration type with a fixed underlyingtype.
Warning: the -fshort-enums switch causes GCC to generatecode that is not binary compatible with code generated without that switch.Use it to conform to a non-default application binary interface.
Warning: the -fshort-wchar switch causes GCC to generatecode that is not binary compatible with code generated without that switch.Use it to conform to a non-default application binary interface.
In C code, this option controls the placement of global variablesdefined without an initializer, known as tentative definitionsin the C standard. Tentative definitions are distinct from declarationsof a variable with the extern keyword, which do not allocate storage.
The default is -fno-common, which specifies that the compiler placesuninitialized global variables in the BSS section of the object file.This inhibits the merging of tentative definitions by the linker so you get amultiple-definition error if the same variable is accidentally defined in morethan one compilation unit.
The -fcommon places uninitialized global variables in a common block.This allows the linker to resolve all tentative definitions of the same variablein different compilation units to the same object, or to a non-tentativedefinition. This behavior is inconsistent with C++, and on many targets impliesa speed and code size penalty on global variable references. It is mainlyuseful to enable legacy code to link without errors.
Put extra commentary information in the generated assembly code tomake it more readable. This option is generally only of use to thosewho actually need to read the generated assembly code (perhaps whiledebugging the compiler itself).
This switch causes the command line used to invoke thecompiler to be recorded into the object file that is being created.This switch is only implemented on some targets and the exact formatof the recording is target and binary file format dependent, but itusually takes the form of a section containing ASCII text. Thisswitch is related to the -fverbose-asm switch, but thatswitch only records information in the assembler output file ascomments, so it never reaches the object file.See also -grecord-gcc-switches for anotherway of storing compiler options into the object file.
Generate position-independent code (PIC) suitable for use in a sharedlibrary, if supported for the target machine. Such code accesses allconstant addresses through a global offset table (GOT). The dynamicloader resolves the GOT entries when the program starts (the dynamicloader is not part of GCC; it is part of the operating system). Ifthe GOT size for the linked executable exceeds a machine-specificmaximum size, you get an error message from the linker indicating that-fpic does not work; in that case, recompile with -fPICinstead. (These maximums are 8k on the SPARC, 28k on AArch64 and 32kon the m68k and RS/6000. The x86 has no such limit.)
Position-independent code requires special support, and therefore worksonly on certain machines. For the x86, GCC supports PIC for System Vbut not for the Sun 386i. Code generated for the IBM RS/6000 is alwaysposition-independent.
If supported for the target machine, emit position-independent code,suitable for dynamic linking and avoiding any limit on the size of theglobal offset table. This option makes a difference on AArch64, m68k,PowerPC and SPARC.
These options are similar to -fpic and -fPIC, but thegenerated position-independent code can be only linked into executables.Usually these options are used to compile code that will be linked usingthe -pie GCC option.
Do not use the PLT for external function calls in position-independent code.Instead, load the callee address at call sites from the GOT and branch to it.This leads to more efficient code by eliminating PLT stubs and exposingGOT loads to optimizations. On architectures such as 32-bit x86 wherePLT stubs expect the GOT pointer in a specific register, this gives moreregister allocation freedom to the compiler.Lazy binding requires use of the PLT;with -fno-plt all external symbols are resolved at load time.
Do not use jump tables for switch statements even where it would bemore efficient than other code generation strategies. This option isof use in conjunction with -fpic or -fPIC forbuilding code that forms part of a dynamic linker and cannotreference the address of a jump table. On some targets, jump tablesdo not require a GOT and this option is not needed.
Treat the register named reg as an allocable register that isclobbered by function calls. It may be allocated for temporaries orvariables that do not live across a call. Functions compiled this waydo not save and restore the register reg.
Treat the register named reg as an allocable register saved byfunctions. It may be allocated even for temporaries or variables thatlive across a call. Functions compiled this way save and restorethe register reg if they use it.
Without a value specified, pack all structure members together withoutholes. When a value is specified (which must be a small power of two), packstructure members according to this value, representing the maximumalignment (that is, objects with default alignment requirements larger thanthis are output potentially unaligned at the next fitting location.
3a8082e126