I have successfully installed MinGW on a Windows 7 32bit machine, and have tried to compile a simple program using either the command line or the MinGW console.
The code has an intentional error in a printf statement:
#include <stdio.h>
#include <stdlib.h>
int main( void )
{
printf("%d
" , 3.14 ) ;
return 0 ;
}
The command gcc -Wall hello.c
gives a correct warning: hello.c:7:2: warning: format '%d' expects argument of type 'int'...
But the command gcc -std=c99 -Wall hello.c
doesn't give any warning.
Both create an executable a.exe ( that runs and gives the same result ).
(Interestingly a command gcc -std=gnu99 -Wall hello.c
gives the warning.)
I don't know if this is a bug, or did the installation go wrong somehow, but both seem unlikely since the compiler works and successfully compiled a larger project( but the same warning of course omitted when using -std=c99 ).
I must be missing some information.
(ps: If someone has a new MinGW install, please test this.)
gcc version 4.8.1 (GCC)
Update 1:
Defining _GNU_SOURCE
before including stdio.h
removes the warning even with gcc -Wall hello.c
.
Update 2( might be less relevant ):
Compiling
printf("%lf
" , 3.14 ) ;
-std=c99
flag outputs: 0.000000
-std=gnu99
outputs: 3.140000
And compiling:
printf("%f
" , 3.14 ) ;
-std=gnu99
and -std=c99
output: 3.140000
Update 3:
Functions that seem to be affected are: printf, fprintf, snprintf, sprintf.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…