I need some help on compiler flags in c++. I\'m using a library that is a port to linux from windows, that has to be compiled with the -malign-double flag, \"for Win32 compa
That's a great flag name! I wonder if there is also a -malign-influence? But seriously this flag controls a slight optimisation:
-malign-double
-mno-align-double
Control whether GCC aligns double, long double,and long long variables on a two word boundary or a one word boundary.Aligning double variables on a two word boundary will produce codethat runs somewhat faster on a ‘Pentium’ at the expense of more memory.
It's unlikely that either the library or your code needs this flag. In general, you should not be using alignment control flags, unless you know exactly what you are doing. If you do feel you need to use them, consult the GCC manual at http://gcc.gnu.org/onlinedocs.
You usually dont need to change alignment settings for modern compilers. Even if compiler will store someting unaligned, program will be not broken.
The only place where it can be needed is stuctures passed between linux and windows version of programm in binary (via files or via network). But in these cases the usage of pragma pack
is better style.
Update: drivers also require binary structures to be bit-by-bit equal with specification.
It could be. If that code expects the stack to be aligned on entry, and your code doesn't ensure that, there is a problem. The same goes for heap allocated objects. If you pass pointers that should be aligned, but aren't, that's wrong too.
At the same time, it could be that just one or two functions require some variables to be aligned, and it never was a problem after all. It would be nice if people are given the time required to understand the code they are responsible for but I guess that's not how it works in the real world.