Environment:
Host OS: Windows X Pro SP 3
GCC:
Using built-in specs.
COLLECT_GCC=C:\MinGW\bin\gcc.exe
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.9.3/lto-wrapper.exe
Target: mingw32
Configured with: ../src/gcc-4.9.3/configure --build=x86_64-pc-linux-gnu --host=mingw32 --prefix=/mingw --disable-win32-registry --target=mingw32 --with-arch=i586 --enable-languages=c,c++,objc,obj-c++,fortran,ada --enable-static --enable-shared --enable-threads --with-dwarf2 --disable-sjlj-exceptions --enable-version-specific-runtime-libs --enable-libstdcxx-debug --with-tune=generic --enable-nls
Thread model: win32
gcc version 4.9.3 (GCC)
Binutils linker: GNU ld (GNU Binutils) 2.25.1
MinGW: 3022000L
Build Environment:
MINGW32_NT-5.1 ANT-519666801B8 1.0.19(0.48/3/2) 2016-07-13 17:45 i686 Msys
The macro __IOCTL_STORAGE_ defined in \ddk\ntddstor.h is not expanded properly.
To reproduce the issude, try to compile the following program with gcc:
#define _XOPEN_SOURCE 700
#include <stdio.h>
#include <winioctl.h>
int main()
{ printf( "IOCTL_STORAGE_EJECT_MEDIA = %1$08d (0x%1$08X)\n",
IOCTL_STORAGE_EJECT_MEDIA
);
return 0;
}
Compilation fails with the following error:
test.c: In function 'main':
test.c:8:7: error: macro "__IOCTL_STORAGE_" requires 3 arguments, but only 2 given
IOCTL_STORAGE_EJECT_MEDIA
^
In file included from c:\mingw\include\ddk\ntdddisk.h:49:0,
from c:\mingw\include\winioctl.h:55,
from test.c:4:
test.c:8:7: error: '__IOCTL_STORAGE_' undeclared (first use in this function)
IOCTL_STORAGE_EJECT_MEDIA
^
test.c:8:7: note: each undeclared identifier is reported only once for each function it appears in
Thanks for the report; this is specific to w32api-3.18.
The issue is caused by the C preprocessor's lazy expansion of macro argument's. It is rather more pervasive than just the
IOCTL_STORAGE_EJECT_MEDIAexample cited, but, continuing with that as an example, we see the expansion of that macro as:with
__IOCTL_STORAGE_defined as:and
__FILE_RD_BUFFEREDdefined (in<ddk/winddk.h>) as:Now, if the C preprocessor expanded macros logically, (i.e. inside parentheses first), we would see
IOCTL_STORAGE_EJECT_MEDIAexpanding initially to:which would be correct. Unfortunately, it doesn't happen that way: expansion occurs from outside to in, and the incorrect number of macro arguments is flagged, without realization that expansion of the inner macro actually would provide the additional argument which is expected.
This afflicts all macros currently defined in terms of
__FILE_RD_BUFFERED, (and similarly,__FILE_RW_BUFFEREDand__FILE_AM_BUFFERED). A possible resolution will be to redefine each of these three macros, to cause, (in the example case),__IOCTL_STORAGE_to be expanded within the expansion of__FILE_RD_BUFFERED, (and similarly, for all other usage, and for each of the other two offending macros), e.g.:I'll work toward such a resolution, and release w32api-3.18.1 ASAP.
This is fixed in
w32api-3.18.1. Although I've flagged it as "include in next release", this is already available in FRS, and may be installed using mingw-get.