#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    28
    Rep Power
    0

    How to bypass the warning and execute the file?


    my problem is, i am using linux platform with gcc to learn C,
    when i try to execute the following file it shows me an warning, how can i bypass it and execute the file ?

    Code:
    # include <stdio.h>
    
    int main () {
    
     char c;
     short s;
     int i;
     long l;
     float f;
     double d;
     long double ld;
     int array [20];
     int *ptr = array;
    
     printf (" size of c= %d\tsizeof (char)=%d", sizeof c, sizeof(char));
     printf ("\n size of s= %d\tsizeof (short)=%d", sizeof s, sizeof(short));
     printf ("\n size of i= %d\tsizeof (int)=%d", sizeof i, sizeof(int));
     printf ("\n size of l= %d\tsizeof (long)=%d", sizeof l, sizeof(long));
     printf ("\n size of f= %d\tsizeof (float)=%d", sizeof f, sizeof(float));
     printf ("\n size of d= %d\tsizeof (double)=%d", sizeof d, sizeof(double));
     printf ("\n size of ld= %d\tsizeof (long double)=%d", sizeof ld, sizeof(long double));
     printf ("\n size of array= %d", sizeof array);
     printf ("\n size of ptr= %d", sizeof ptr);
     return 0;
    }
    waning :
    Code:
    fig7.17.c: In function ‘main’:
    fig7.17.c:20:2: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat]
    fig7.17.c:20:2: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘long unsigned int’ [-Wformat]
    fig7.17.c:21:2: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat]
    fig7.17.c:21:2: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘long unsigned int’ [-Wformat]
    fig7.17.c:22:2: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat]
    fig7.17.c:22:2: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘long unsigned int’ [-Wformat]
    fig7.17.c:23:2: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat]
    fig7.17.c:23:2: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘long unsigned int’ [-Wformat]
    fig7.17.c:24:2: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat]
    fig7.17.c:24:2: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘long unsigned int’ [-Wformat]
    fig7.17.c:25:2: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat]
    fig7.17.c:25:2: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘long unsigned int’ [-Wformat]
    fig7.17.c:26:2: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat]
    fig7.17.c:26:2: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘long unsigned int’ [-Wformat]
    fig7.17.c:27:2: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat]
    fig7.17.c:28:2: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat]
    Thanks in advance
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    159
    Rep Power
    19
    But the problem is it shows me some warning, and i can not execute this file. Now my question is how can i by pass this warning and execute the follwoing file ?
    Best answer, you don't. Fix the problems. Those messages are very serious errors that should be fixed. Find and read the documentation for those functions (printf) and use the correct format specifiers for the type of variables.


    Jim
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    28
    Rep Power
    0
    I think i found a solution to my own problem, I guess it compiles the program and gives me warning but i can get a file which can be executable and it works fine. but here is a quesiton pops into my mind is if i keep doing it is it going to crush my system?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    159
    Rep Power
    19
    but here is a quesiton pops into my mind is if i keep doing it is it going to crush my system?
    Ignoring warnings is never a good idea. Always treat warnings as errors and fix them.

    Jim
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    28
    Rep Power
    0
    Originally Posted by jimblumberg
    Ignoring warnings is never a good idea. Always treat warnings as errors and fix them.

    Jim
    Thanks Jim, I ll try to do it. but I saw the manual and probably couldnt understant exactly what should i use. I think i have to work a little harder to comeup with a solution.
  10. #6
  11. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,109
    Rep Power
    1803
    It is not about "bypassing the warning" - that should never be your aim - but rather about correcting your code.

    %lu rather than %d

    Really... read the documentation!

IMN logo majestic logo threadwatch logo seochat tools logo