MinGw Bug (Compound Literals C99)

AceInfinity

Emeritus, Contributor
Joined
Feb 21, 2012
Posts
1,728
Location
Canada
I noticed some unexpected behavior when using compound literals in C under MinGw, but also Microsoft's compiler (which wasn't too surprising since they kind of half-fully support C99, and focus more on C++ support).

Ideone.com - HLn9Hb - Online IDE & Debugging Tool

^ This code compiled under a non-port of gcc (strict C99) will yield the proper time result string.

Other tests on my MinGw compiler result in a pointer that is not null, but asctime() returns a NULL string and therefore nothing is really output to stdout.

Code:
puts(asctime(&(const struct tm) { .tm_hour = 1, .tm_min = 2, .tm_sec = 3}));

I tried assigning the address to a pointer from outside of the function call, with the same bad result. The scope shouldn't end until the function returns really, so a dangling pointer is not the issue here. Compiles and executes fine with the expected result in clang (tested 3.7).

My own MinGw version: gcc (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 5.4.0

Tested on bash on Windows with gcc installed, and the correct string was output to stdout. (gcc (Ubuntu 4.9.4-2ubuntu1~14.04.1) 4.9.4)

Filed a bug report to see what people say. :grin1:

Same command line from makefile for both compilers (gcc on bash, gcc on Windows (MinGw))
` gcc -std=c99 -Wall -Wextra -pedantic -fstrict-aliasing -O2 main.c -static-libgcc -o main
NGnM7Px.png
 
Last edited:
Still doesn't work in build: gcc (i686-posix-dwarf-rev1, Built by MinGW-W64 project) 6.2.0

My submitted bug report has no traction currently, no updates on the ticket. Best bet is to stick with a compiler like clang since I'm sure that should work. :)
 

Has Sysnative Forums helped you? Please consider donating to help us support the site!

Back
Top