gcc -Wall -pedantic

This is a discussion on gcc -Wall -pedantic within the C Programming forums, part of the General Programming Boards category; Hi! I have to compile code for an assignment with the gcc options -Wall -pedantic. there must not be warnings ...

  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
    "I Win!" by U. Lose vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,754
    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
    To be or not to be == true

  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
    23,628
    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
    "I Win!" by U. Lose vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,754
    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?
    To be or not to be == true

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, 04:24 AM
  5. gcc
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 10-22-2003, 03:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21