The Windows SDK include files do not define a PACKED macro anywhere.
The attached file compiles without warning or error with Microsoft Compilers.
MINGW produces:
H:\MinGW\Bugs>gcc GCCPACKEDBug.c
GCCPACKEDBug.c:4:0: warning: "PACKED" redefined
h:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/windef.h:71:0: note: this is the location of the previous definition
H:\MinGW\Bugs>gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=h:/mingw/bin/../libexec/gcc/mingw32/4.5.2/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.5.2/configure --enable-languages=c,c++,ada,fortran,objc,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --
enable-shared --enable-libgomp --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs --disable-we
rror --build=mingw32 --prefix=/mingw
Thread model: win32
gcc version 4.5.2 (GCC)
H:\MinGW\Bugs>ld -v
GNU ld (GNU Binutils) 2.21
#define __MINGW32_VERSION 3.18
#define __W32API_VERSION 3.17
OS: Windows 7 Pro x64
PACKED bug demo
You don't show the contents of GCCPACKEDBug.c but I'm guessing this is your error in your code on line 4 where you've used a reserved word. This is not a bug in gcc or w32api. To correct the issue you will need to not use the reserved word in your code.
Earnie,
I'm reopening this, since in this case I believe the OP may have a point.
The definition, in MinGW's windef.h is
#define PACKED __attribute__((packed))
That's a GCC, (and hence MinGW), specific attribute. As such, it would not be likely that it is defined in any Microsoft header, (and its use almost certainly isn't documented anywhere outside that particular MinGW header itself); it should NOT have been defined thus in a MinGW system header, (in a form which would be a valid macro name in user code). It should be
#define __MINGW_PACKED__
or some such, to mark it clearly as a MinGW implementation specific reserved name, and so avoid potential conflict with any user space name.
Of course, when making such a change, all clients must be adjusted accordingly; I see two additional (alternative) #defines in windef.h, and only one reference anywhere else, (in wincon.h):
typedef struct _KEY_EVENT_RECORD {
...
}
#ifdef __GNUC__
/* gcc's alignment is not what win32 expects */
PACKED
#endif
KEY_EVENT_RECORD;
which does rather beg the question: is there really any value in defining it at all? Surely
typedef struct _KEY_EVENT_RECORD {
...
}
#ifdef __GNUC__
/* gcc's alignment is not what win32 expects */
__attribute__((packed))
#endif
KEY_EVENT_RECORD;
is just as good, (and is possibly clearer in intent).
Hi earnie,
I didn't show the contents since I provided the 6 line program. This working program is a subset of a real program which demonstrated this issue.
Both the original real program AND the 6 line demo compile cleanly using any of the Microsoft compilers.
I wasn't looking for a workaround when using MinGW, I was looking for MinGW to work as a replacement for the Microsoft compiler.
If you are declaring that the behavior I'm seeing is "as Documented", please provide a reference to the relevant documentation. There is no documentation on the Microsoft compilers which might declare this issue as reserved since it works just fine in there.
Please reopen this issue and actually address what is happening.
Mark,
I guess our respective follow-up comments crossed in the post, (as it were).
You will note that I believe Earnie's closure of this ticket to have been premature; I have already reopened the issue. I'm assigning to Chris Sutcliffe for resolution. In the meantime, you may wish to modify your own local copies of the affected headers, to remove the three #defines of PACKED from windef.h, and to replace the one reference in wincon.h with __attribute__((packed))
Sorry for the noise, I failed to see the attached file and I didn't look at the windef.h file to notice that PACKED was created for MinGW if the compiler is GCC. I'll stop making assumptions now and go hide in my corner. I agree with the solution Keith provides.
Thank you for the report, I've committed a fix to CVS.