Hello, I'm encountering a similar/related issue with PRIdMAX on mingw32-gcc 4.8.2.
In short, when using gnulib in my project and cross-compiling with mingw32-gcc 4.8.2 somehow the PRIdMAX becomes "lld" instead of "I64d". I was able to reproduce it with GNU Hello (long details below). perhaps I'm doing something incorrect and you might be able to suggest a fix? An incorrect usage of gnulib's 'inttypes' or 'stdint' modules? Thanks, - assaf On 05/22/2015 08:08 AM, Eric Blake wrote:
/* Do this test only on MingW. */ char PRIdMAX_is_I64d[sizeof PRIdMAX == sizeof "I64d" ? 1 : -1]; which will give us a compile-time failure if PRIdMAX is "lld".
I've tested it like so: -1- The system is Ubuntu 14.04.2, with mingw from the standard package. $ dpkg -l gcc-mingw-w64-x86-64 ii gcc-mingw-w64-x86-64 4.8.2-10ubuntu2 amd64 GNU C compiler for MinGW-w64 targeting Win64 $ x86_64-w64-mingw32-gcc -v gcc version 4.8.2 (GCC) -2- Checking a simple C file without gnulib, PRIdMAX is correctly defined as "I64d": $ cat 1.c #include <stdint.h> #include <inttypes.h> int main(int argc, char* argv[]) { char PRIdMAX_is_I64d[sizeof PRIdMAX == sizeof "I64d" ? 1 : -1]; return 0; } $ x86_64-w64-mingw32-gcc -o 1 1.c # ( No compilation errors ) $ x86_64-w64-mingw32-gcc -E 1.c | tail -n5 int main(int argc, char* argv[]) { char PRIdMAX_is_I64d[sizeof "I64d" == sizeof "I64d" ? 1 : -1]; return 0; } -3- Checking with gnulib's internal tests, PRIdMAX is still correct: # Create unit-tests for 'inttypes' module git clone git://git.sv.gnu.org/gnulib.git cd gnulib/ ./gnulib-tool --create-testdir --dir foo inttypes cd foo # add the compile-time check sed -i '/return 0/ichar PRIdMAX_is_I64d[sizeof PRIdMAX == sizeof "I64d" ? 1 : -1];' gltests/test-inttypes.c ./configure --host=x86_64-w64-mingw32 make ## (no compilation errors) ## Verify the macro expansion: rm gltests/test-inttypes.o make CFLAGS="-E" grep PRI.MAX gltests/test-inttypes.o == char PRIdMAX_is_I64d[sizeof "I64d" == sizeof "I64d" ? 1 : -1]; == -4- However, Adding the same check to a 'real' project which uses gnulib (GNU Hello), somehow PRIdMAX is reverted to "lld". Perhaps some other headers are missing or additional gnulib modules are needed? git clone git://git.sv.gnu.org/hello.git cd hello # Needed as 'LC_MESSAGES' fails to compile with mingw32, not related to this issue sed -i '/setlocale/s/LC_MESSAGES/LC_ALL/' src/hello.c # Use gnulib modules inttypes and stdint sed -i '/gnulib_modules/ainttypes\nstdint' bootstrap.conf # Add #includes to the C file sed -i '/<config\.h>/a#include <stdint.h>\n#include <inttypes.h>' src/hello.c # Add the compile-type check for PRIdMAX sed -i '/Forward declarations/ichar PRIdMAX_is_I64d[sizeof PRIdMAX == sizeof "I64d" ? 1 : -1];' src/hello.c # Try to compile ./bootstrap ./configure --host=x86_64-w64-mingw32 make And it fails with: ... x86_64-w64-mingw32-gcc -DLOCALEDIR=\"/usr/local/share/locale\" -DHAVE_CONFIG_H -I. -Ilib -I./lib -Isrc -I./src \ -g -O2 -MT src/hello.o -MD -MP -MF $depbase.Tpo -c -o src/hello.o src/hello.c &&\ mv -f $depbase.Tpo $depbase.Po src/hello.c:29:6: error: size of array 'PRIdMAX_is_I64d' is negative char PRIdMAX_is_I64d[sizeof PRIdMAX == sizeof "I64d" ? 1 : -1]; ^ make[2]: *** [src/hello.o] Error 1 make[2]: Leaving directory `/tmp/j/hello' Checking the macro expansion: rm -f src/hello.o make CFLAGS="-E" grep PRI.MAX src/hello.o == char PRIdMAX_is_I64d[sizeof "lld" == sizeof "I64d" ? 1 : -1]; == In my project I see the same error as with GNU Hello: PRIdMAX is incorrect, despite the underlying definition being "I64d".