From: "Tonu Aas" Newsgroups: comp.os.msdos.djgpp References: <96eb2770 DOT 0206270530 DOT 3d2253dc AT posting DOT google DOT com> Subject: Re: How to align members/data under gcc/DJGPP? Date: Thu, 27 Jun 2002 19:06:02 +0300 Lines: 83 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 NNTP-Posting-Host: ids.ids.ee Message-ID: <3d1b37f1$1@news.infonet.ee> X-Trace: news.infonet.ee 1025193969 ids.ids.ee (27 Jun 2002 18:06:09 +0200) Organization: INFONET.EE To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com > I can't find in FAQ (sorry, maybe I missed it), how to align struct > members under gcc/DJGPP? What is pragma/option doing this? I use header files for that: struct aligned_struct { char a_default; #include "align4.h" char a_4; #include "popalign.h" char aa_default; } Works well with several compilers so far... (also gcc) Its unbelievable that aligning isnt part of C standard, but it is. Writing protable code in C is hard work. Look for some portabel code: 50% of text are #ifdef-s for several compilers, OS-s and platforms stupidities. --------------------- align1.h: #ifndef _MSC_VER #pragma nopackwarning #endif #if !(defined(lint) || defined(_lint)) # ifndef RC_INVOKED # if(_MSC_VER >= 800) || (defined(__BORLANDC__)) # pragma warning(disable:4103) # if !defined(MIDL_PASS) || defined(__midl) # pragma pack(push) # endif # pragma pack(1) # else # pragma pack(1) # endif # endif #endif ----------------------- align2.h: #pragma nopackwarning #if !(defined(lint) || defined(_lint)) # ifndef RC_INVOKED # if(_MSC_VER >= 800) || (defined(__BORLANDC__)) # pragma warning(disable:4103) # if !defined(MIDL_PASS) || defined(__midl) # pragma pack(push) # endif # pragma pack(2) # else # pragma pack(2) # endif # endif // ndef RC_INVOKED #endif // !(defined(lint) || defined(_lint))#pragma nopackwarning -------------- ... and so on, and after ----------------- popalign.h: #ifndef _MSC_VER #pragma nopackwarning #endif #if !(defined(lint) || defined(_lint)) # if(_MSC_VER >= 800) || defined(__BORLANDC__) # pragma warning(disable:4103) # if !defined(MIDL_PASS) || defined(__midl) # pragma pack(pop) # else # pragma pack() # endif # else # pragma pack() # endif #endif