GCC Warnings

This is a discussion on GCC Warnings within the C Programming forums, part of the General Programming Boards category; I was trying to get rid of all of the warnings on my program so I compiled with Code: gcc ...

  1. #1
    Registered User 00Sven's Avatar
    Join Date
    Feb 2006
    Posts
    127

    GCC Warnings

    I was trying to get rid of all of the warnings on my program so I compiled with
    Code:
    gcc main.c -o main.exe -W -Wall -ansi
    I did this and corrected some things but now all that I have left is to get rid of the implicit declarations. I have a bunch of warnings such as
    Code:
    main.c:421: warning: implicit declaration of function 'toupper'
    I have these for a few functions. How do I get rid of them?
    ~Sven
    Windows XP Home Edition - Dev-C++ 4.9.9.2
    Quote Originally Posted by "The C Programming Language" by Brian W. Kernignhan and Dennis M. Ritchie
    int fflush(FILE *stream)
    On an output stream, fflush causes any buffered but unwritten data to be written; On an input stream, the effect is undefined. It returns EOF for a write error, and zero otherwise. fflush(NULL) flushes all output streams.
    board.theprogrammingsite.com

  2. #2
    Registered User
    Join Date
    Jan 2006
    Location
    Berkeley, Ca
    Posts
    195
    The warning means that the function is missing the corresponding protoype. In this case, the prototype for toupper() is in the header ctype.h

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    1. Read the manual page
    man toupper

    2. The response you get
    TOUPPER(3) Linux Programmerís Manual TOUPPER(3)

    NAME
    toupper, tolower - convert letter to upper or lower case

    SYNOPSIS
    #include <ctype.h>

    3. Add the include files to the source code

    4. rinse and repeat.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User 00Sven's Avatar
    Join Date
    Feb 2006
    Posts
    127
    Now I am getting the same error for the sleep() function. What header file is this in?
    ~Sven
    Windows XP Home Edition - Dev-C++ 4.9.9.2
    Quote Originally Posted by "The C Programming Language" by Brian W. Kernignhan and Dennis M. Ritchie
    int fflush(FILE *stream)
    On an output stream, fflush causes any buffered but unwritten data to be written; On an input stream, the effect is undefined. It returns EOF for a write error, and zero otherwise. fflush(NULL) flushes all output streams.
    board.theprogrammingsite.com

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    Sometimes, you have to specify the appropriate manual section

    $ man sleep
    $ man 2 sleep
    No entry for sleep in section 2 of the manual
    $ man 3 sleep
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User 00Sven's Avatar
    Join Date
    Feb 2006
    Posts
    127
    What do you mean? What is $ man???
    ~Sven
    Windows XP Home Edition - Dev-C++ 4.9.9.2
    Quote Originally Posted by "The C Programming Language" by Brian W. Kernignhan and Dennis M. Ritchie
    int fflush(FILE *stream)
    On an output stream, fflush causes any buffered but unwritten data to be written; On an input stream, the effect is undefined. It returns EOF for a write error, and zero otherwise. fflush(NULL) flushes all output streams.
    board.theprogrammingsite.com

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    Why are you still programming?
    Knowing what manual pages are, and how to read them is a fundamental part of the job.

    Or maybe if you're using some glossy IDE, point your cursor at the function and press F1

    I'm not going to sit here and spoon feed every single function you've guessed at just to tell you which header file you should be using.
    If you haven't RTFM, how the hell do you know if you're even using it right?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #8
    Registered User 00Sven's Avatar
    Join Date
    Feb 2006
    Posts
    127
    I have googled the sleep function and found that it is in unistd.h but I have that included already and still get the error. I am not using Linux if the manual pages are something only in Linux. I have checked my IDE help and there is nothing there about specific functions.
    ~Sven
    Windows XP Home Edition - Dev-C++ 4.9.9.2
    Quote Originally Posted by "The C Programming Language" by Brian W. Kernignhan and Dennis M. Ritchie
    int fflush(FILE *stream)
    On an output stream, fflush causes any buffered but unwritten data to be written; On an input stream, the effect is undefined. It returns EOF for a write error, and zero otherwise. fflush(NULL) flushes all output streams.
    board.theprogrammingsite.com

  9. #9
    Registered User
    Join Date
    Apr 2006
    Posts
    2
    gcc main.c -o main.exe -W -Wall -ansi
    So you're under Windows.

    What about windows.h

  10. #10
    Registered User 00Sven's Avatar
    Join Date
    Feb 2006
    Posts
    127
    Still getting the warning. Oh well, the program works so I guess I will just leave it.
    ~Sven
    Windows XP Home Edition - Dev-C++ 4.9.9.2
    Quote Originally Posted by "The C Programming Language" by Brian W. Kernignhan and Dennis M. Ritchie
    int fflush(FILE *stream)
    On an output stream, fflush causes any buffered but unwritten data to be written; On an input stream, the effect is undefined. It returns EOF for a write error, and zero otherwise. fflush(NULL) flushes all output streams.
    board.theprogrammingsite.com

  11. #11
    Registered User
    Join Date
    Mar 2006
    Posts
    18
    googled:

    Code:
    If you're on Windows, include 'windows.h' and use void Sleep(DWORD milliseconds)
    or DWORD SleepEx(DWORD dwMilliseconds, BOOL bAlertable)
    I think microsoft also included 'sleep(time_t seconds)' in their version of stdlib.h
    http://www.free2code.net/plugins/for...w.php?f=3&p=77

  12. #12
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by 00Sven
    Still getting the warning. Oh well, the program works so I guess I will just leave it.
    ~Sven
    Are you sure you included the correct filename, correctly spelt?
    Sure you saved the file before recompiling it?

    I just got rid of a dozen or so warnings and have none now

    I found the easiest way to find the include file was to use
    windows search to search in the include file directory in
    /DJGCC.

    Maybe try moving the include statement so it is one of the
    first (after stdio.h)?

    Anyway mine looks real neat now and 'real' errors don't
    scroll of the screen.

  13. #13
    Registered User 00Sven's Avatar
    Join Date
    Feb 2006
    Posts
    127
    I found a better solution, take sleep out of the program. It was pretty pointless in how it was used so now it is gone.
    ~Sven
    Windows XP Home Edition - Dev-C++ 4.9.9.2
    Quote Originally Posted by "The C Programming Language" by Brian W. Kernignhan and Dennis M. Ritchie
    int fflush(FILE *stream)
    On an output stream, fflush causes any buffered but unwritten data to be written; On an input stream, the effect is undefined. It returns EOF for a write error, and zero otherwise. fflush(NULL) flushes all output streams.
    board.theprogrammingsite.com

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. How do I disable these GCC warnings?
    By cpjust in forum C Programming
    Replies: 12
    Last Post: 10-20-2007, 09:45 PM
  3. Definitions for gcc errors and warnings?
    By cpjust in forum C Programming
    Replies: 12
    Last Post: 10-04-2007, 09:18 AM
  4. Replies: 4
    Last Post: 09-02-2007, 08:47 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM

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