Web lists-archives.com

[Mingw-users] -Wall and -ansi conflict for printf




The following simple source contains a error in the second printf

& shouid  be notified to be an error with a warning

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#include<stdio.h>

/*example1.c*/
int main()
{
     int dim;
     printf ("Enter a number ");
     scanf ("%d", &dim);
     printf ("The entered number is %d\n ", &dim);
     return (0);
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

The command line
gcc -Wall -ansi example1.c
on
gcc version 5.2.1  (Ubuntu 15.10)
gcc version 4.8.3  (mingw-w64 on msysy and Win10)
give the correct diagnostic:

example1.c: In function ‘main’:
example1.c:9:10: warning: format ‘%d’ expects argument of type ‘int’, 
but argument 2 has type ‘int *’ [-Wformat=]
   printf ("The entered number is %d\n ", &dim);


Instead the same command line on
gcc version 4.9.3  (mingw on msysy and Win10)
gcc version 4.9.3  (mingw on msysy and Win10)
gcc version 4.7.1  (mingw on msysy and Win10)
is not able to find the error
while without -ansi  (.i.e., gcc -Wall example1.c) the error is detected

-------------------------------------------------------------------------------------
The problem seems related to printf only, as  for the following source


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#include<stdio.h>

/*example2.c*/
int main()
{
     int dim;
     printf ("Enter a number ");
     scanf ("%d", dim);
     printf ("The entered number is %d\n ", dim);
     return (0);
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


gcc -Wall -ansi example2.c

all noticed versions of gcc give the following diagnostic

example2.c: In function ‘main’:
example2.c:8:9: warning: format ‘%d’ expects argument of type ‘int *’, 
but argument 2 has type ‘int’ [-Wformat=]
   scanf ("%d", dim);
          ^
example2.c:8:2: warning: ‘dim’ is used uninitialized in this function 
[-Wuninitialized]
   scanf ("%d", dim);







------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785111&iu=/4140
_______________________________________________
MinGW-users mailing list
MinGW-users@xxxxxxxxxxxxxxxxxxxxx

This list observes the Etiquette found at 
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:mingw-users-request@xxxxxxxxxxxxxxxxxxxxx?subject=unsubscribe