Are the differences in structure different?

Normally I would have a good smile, but her so mean her is not even funny. How the hell can a structure differ from one file to another?

I had this structure:

typedef struct pp_sig_s { [...] int flags; size_t max; bool is_reversed; unsigned int sig[64]; size_t byref; [...] } pp_sig_t; 

It was defined in the expression "header01.h" Some function that I use is located in "program01.cpp" Declared this way

 void PrintSig(pp_sig_t *s); // prints the content of sig[64] array in pp_sig_t for test purposes 

Another pp_sig_t object, called g_sig_1, was defined in "header02.cpp" ... This .cpp includes, of course, the header01.h I call this print procedure inside it

 PrintSig(&g_sig_1); 

I noticed that the print result is different from the actual content. Say sig contains 0xE8, then 0xE800 is printed

Then, I thought, about 2 hours of research, this could be a leveling structure.

I try this ...

Declaring a structure this way in header01.h

 #pragma push() #pragma pack(4) typedef struct pp_sig_s { [...] int flags; size_t max; bool is_reversed; unsigned int sig[64]; size_t byref; [...] } pp_sig_t; #pragma pop() 

And suddenly everything works fine ...

So basically it looks like if the structure offsets in program01.cpp were, I think, different from program02.cpp ...

How the hell can a structure differ from one file to another? How can we avoid this without using pragmas? Could this be caused by a compiler error (I am using Intel C ++ XE Composer 2013 Update 2, on Linux)?

+4
source share
1 answer

This was probably caused by the prime alignment, which was in scope when one of the files included the header, but not when the other was executing.

+1
source

Source: https://habr.com/ru/post/1481052/


All Articles