LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   #pragma pack directive (https://www.linuxquestions.org/questions/programming-9/pragma-pack-directive-486694/)

rajesh_b 09-25-2006 12:28 AM

#pragma pack directive
 
hi,
Can any body tell me
#pragma pack directive in visual studio is ISO/ANSI compilant or it is visual studio specific one. If i use this directive the code will be portable or not?


Regards,
Rajesh

paulsm4 09-25-2006 12:56 AM

I don't know which version of Visual Studio you're using ... but the one I'm familiar with (MSVC++ 5/6) is absolutely not portable.

Most compilers have some equivalent for byte alignment; sometimes pragma's (like MSVC), sometimes compiler options. Here's an example:
Code:

#if defined(WATCOM)
  _Packed
#elif defined(WIN32)
  #pragma pack(push, 1)
#endif
struct o_backup_bowler_rec
{
  char name[21+1];
  char init[3+1];
  WORD bowler_num;
  BYTE keeping;
#if defined(LINUX)
} __attribute__ ((packed));
#elif defined(WIN32)
};
#pragma pack (pop)
#else
};
#endif


rajesh_b 09-25-2006 04:05 AM

hi
 
thanks for the reply.
Then i need to see the compiler manual to see what needs to be done for packing.

Regards,
Rajesh


All times are GMT -5. The time now is 06:14 AM.