Menu

Turn on Compiler warnings

vca
2008-01-10
2012-09-26
  • vca

    vca - 2008-01-10

    Hello,
    I'm running Dev-C++ 4.9.9.2, Windows XP Pro.
    After having turned on the compiler warnings
    with:-W -Wall -ansi -pedantic -O2; I'm receiving
    the warnings listed below.

    How do I resolve this problem?

    Thank you,

    Pellum.

    /Filename devproc.c/

    include <stdlib.h>

    include <stdio.h>

    include <ctype.h>

    void process_file(FILE *fp);

    int main(void)
    {
    FILE *fp = fopen("test.txt", "r");

    if(fp)
    {
        process_file(fp);
        fclose(fp);
    }
    else
    {
        perror(&quot;error opening the file&quot;);
    
    }
    getchar();
    return 0;
    

    }
    /**********/
    void process_file(FILE *fp)
    {
    int ch;
    int nalpha = 0;
    int ndigit = 0;
    int npunct = 0;
    int nspace = 0;

    while((ch= fgetc(fp)) != EOF)
    {
        if(isalpha(ch))
        {
            ++nalpha;
        }else if(isdigit(ch))
        {
            ++ndigit;
        }else if(ispunct(ch))
        {
            ++npunct;
        }else if(isspace(ch))
        {
            ++nspace;
        }
    }
    
    printf(&quot;alphabetic characters: %d\n&quot;, nalpha);
    printf(&quot;digit characters: %d\n&quot;, ndigit);
    printf(&quot;punctuation characters: %d\n&quot;, npunct);
    printf(&quot;whitespace characters: %d\n&quot;, nspace);
    
    return;
    

    }
    /************/
    Warnings:

    Compiler: Default compiler
    Building Makefile: "D:\mydevc++\Makefile.win"
    Executing make...
    make.exe -f "D:\mydevc++\Makefile.win" all
    gcc.exe -c devproc.c -o devproc.o -I"C:/Dev-Cpp/include" -W -Wall -ansi -pedantic -O2

    In file included from C:/Dev-Cpp/include/stdio.h:26,
    from devproc.c:2:
    C:/Dev-Cpp/include/stddef.h:6:2: warning: #include_next is a GCC extension
    In file included from C:/Dev-Cpp/include/stdio.h:28,
    from devproc.c:2:

    C:/Dev-Cpp/include/stdarg.h:6:2: warning: #include_next is a GCC extension
    In file included from devproc.c:2:

    C:/Dev-Cpp/include/stdio.h:330: warning: ISO C90 does not support `long long'

    In file included from C:/Dev-Cpp/include/ctype.h:20,
    from devproc.c:3:
    C:/Dev-Cpp/include/stddef.h:6:2: warning: #include_next is a GCC extension

    gcc.exe devproc.o -o "devproc.exe" -L"C:/Dev-Cpp/lib"

    Execution terminated
    Compilation successful
    /***************/

     
    • cpns

      cpns - 2008-01-10

      -W is the option to "inhibit all warning messages". Why would you use that with -Wall !?

      If you don't want pedantic warnings, don't use -pedantic! It is not unreasonable for compiler supplied headers to use compiler extensions, but if you ask to be warned about such things you will be! You should read and understand the consequences of the -pedantic option. The official GCC manual server is unresponsive as I write this so here's an alternative location: http://developer.apple.com/documentation/developertools/gcc-4.0.1/gcc/Warning-Options.html

      As the warning clearly explains "long long" is not a C90 data type. In C90 it is a compiler extension, and you asked it to be pedantic - so it is! You could specify -std=C99 (and remove -ansi, as this implies -std=C89) or you could just stop being pedantic!

      For C compilation (or where you are using the C library formatted I/O functions in C++) I would recommend:

      -Wall -Werror -Wformat

      For C only -Wshadow may be useful, but in C++ if you are in the habit of declaring "using namespace std ;" it will cause far too much trouble since the C++ standard library contains many symbols that would be considered poorly named in the global namespace. Also in C++ the use if inheritance hierarchies makes shadowing likley and cumbersome to avoid.

      You may wish to use -ansi if you want to restrict yourself to the C89/C90 standard. This will aid protabiliy since not all compilers support all C99 features, but -pedantic will to little to aid portability.

      Clifford

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.