From: Ian Chapman Newsgroups: comp.os.msdos.djgpp Subject: PACKED situation Date: Thu, 12 Mar 1998 07:33:45 -0500 Organization: Nortel Lines: 96 Message-ID: <3507D629.73E2@nortel.ca> Reply-To: ichapman AT nortel DOT ca NNTP-Posting-Host: bcarib90.bnr.ca Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Hi all, standard problem with PACKED taken from faq. It's a bug in a version of djgpp which according to the faq s been fixed in the djdev201.zip version. The faq says that the structure gets messed up. I get the error below where the ";" is stated as missing. I've been running djdev201.zip derived files for about a year. So version should not be my problem. typedef struct { DWORD style; DWORD dwExtendedStyle; short x; short y; short cx; short cy; WORD id; } PACKED DLGITEMTEMPLATE; //Error ; missing after struct declaration. From the FAQ 22.10 C++ doesn't pack structs! =============================== **Q*: When I use `struct ffblk' from the header `dir.h' in a C++ program, I get garbage in some fields of the structure!* *A* : There is a known bug in GCC 2.7.2: the C++ compiler effectively ignores the `__attribute__((packed))' directives, so the structures end up being not packed. DJGPP v2.01 comes with GCC 2.7.2.1 which corrected that bug, so upgrade. As a work-around, surround the declaration of the structure that needs to be packed with `#pragma pack', like this: #ifdef __cplusplus #pragma pack(1) #endif . . . #ifdef __cplusplus #pragma pack() #endif //============================================================= So I tried this and still get the error:- #ifdef __cplusplus #pragma Pack(1) #endif typedef struct { DWORD style; DWORD dwExtendedStyle; short x; short y; short cx; short cy; WORD id; } PACKED DLGITEMTEMPLATE; //Error ; missing after struct declaration. #ifdef __cplusplus #pragma Pack() #endif // So what have I done wrong? This is a part of structure.h file from cygnus which is all about getting unix stuff running under win95. I'm using the cygnus gnu windows.h and associated files in place of MS as I think it's a more appropriate starting point for what I'm doing. Should I try changing the file names from dot.cpp to dot.cc? ==================================================== After looking in the mail archives I find this advice:- //====================================================== struct any { long l1,l2 PACKED; byte b: PACKED; int i: PACKED; }; is WRONG. The correct way to do it is: struct any { long l1 PACKED; long l2 PACKED; byte b: PACKED; int i: PACKED; }; Assuming:- #ifndef PACKED #ifdef __GNUC__ #define PACKED __attribute__ ((packed)) #else #define PACKED #endif #endif //================================================= Quite a change, is this what I have to do. Hoping for some of that great help Regards Ian.