Click to See Complete Forum and Search --> : #pragma pack(): Is it Microsoft compiler dependent?


April 6th, 1999, 02:51 PM
Is the preprocessor command:
#pragma pack(...)

A Microsoft compiler dependant command? I looked through the help and couldn't really find out for sure.

I'm making a DLL which will use a struct data type. The struct will be declared in a header file which will be used by the DLL project itself and programs using the DLL.

I want to make sure that the other programs compile the structure under the same packing style. If all programs were using Microsoft VC++ compilers, I could use #pragma pack(16).

However, some programs might be using a different compiler. So putting #pragma pack(16) in the header would confuse the other compiler.

If there is something else besides #pragma pack which ensures a specific structure layout over all compilers, I'd love to know it.

Thanks
Steve

April 6th, 1999, 03:56 PM
I'm fairly sure the pragma pack is Microsoft specific and was only introduced
within the 32 bit compilers. Pragmas are often used by vendors in this way and I'd be surprised if any other vendor supports this. I occasionally use a Unix compiler and I can't find any reference to it in there. The other vendors will no doubt just ignore it.

The best I can suggest is that you could also add a check to ensure you're building using the Microsoft compiler and flag an error/warning if another compiler is used.