Thread: gcc -Wall -pedantic

  1. #1
    gcc -Wall -pedantic *.c
    Join Date
    Jan 2009
    Location
    London
    Posts
    60

    gcc -Wall -pedantic

    Hi! I have to compile code for an assignment with the gcc options -Wall -pedantic.
    there must not be warnings in order to submit it, so here there's the output

    Code:
    [cls2@it151 DPLAN]$ gcc -Wall -pedantic lbase.c
    lbase.c: In function ‘convertiEvento’:
    lbase.c:66: warning: ISO C90 forbids mixed declarations and code
    lbase.c:67: warning: implicit declaration of function ‘snprintf’
    lbase.c:67: warning: incompatible implicit declaration of built-in function ‘snprintf’
    /usr/lib/gcc/i386-redhat-linux/4.3.2/../../../crt1.o: In function `_start':
    (.text+0x18): undefined reference to `main'
    collect2: ld returned 1 exit status
    The main is in another file so the problem is only with the snprintf().
    I had a look to the man page of snprintf:

    Code:
       Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
    
           snprintf(), vsnprintf(): _BSD_SOURCE || _XOPEN_SOURCE >= 500 ||
           _ISOC99_SOURCE; or cc -std=c99
    I tried to define those variables but unfortunately the warning is still there!
    Any idea?

    Cheers

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    first warning means you have variable declarations like
    int i;
    after other code

    C90 requires all declarations to be at the beginnign of the block

    about snprintf - you do not need to declare it manually - rather include the correct header file
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    gcc -Wall -pedantic *.c
    Join Date
    Jan 2009
    Location
    London
    Posts
    60
    Yes you're right about the declarations... i remembered!... But which file should i include for the snprintf?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by flexo87
    But which file should i include for the snprintf?
    The standard header <stdio.h>
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    gcc -Wall -pedantic *.c
    Join Date
    Jan 2009
    Location
    London
    Posts
    60
    That's it! Thanks

  6. #6
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by flexo87 View Post
    Yes you're right about the declarations... i remembered!... But which file should i include for the snprintf?
    doesn't your man page specified it?

    or it took you less time to write a question on the board than type "man snprintf" on the console?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  2. Compiles on gcc 3.3 but not on gcc 4.0.3
    By cunnus88 in forum C++ Programming
    Replies: 5
    Last Post: 03-29-2007, 12:24 PM
  3. gcc Wall versus pedantic
    By Bajanine in forum C Programming
    Replies: 2
    Last Post: 04-28-2005, 10:58 AM
  4. The best gcc options? Just everyday use.
    By Kleid-0 in forum C Programming
    Replies: 12
    Last Post: 12-27-2004, 05:24 AM
  5. gcc
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 10-22-2003, 03:46 PM