how can I get warning ?

Discussion in 'C Programming' started by DaVinci, Oct 17, 2006.

  1. DaVinci

    DaVinci Guest

    int main()
    {
    double d = 33.33;
    int i = d;
    return 0;
    }

    Makefile:

    gcc -c -g -Wall -std=c99 test.c
    but I can't get any warning information.
    how can I get the warning on the type converation?
    DaVinci, Oct 17, 2006
    #1
    1. Advertising

  2. DaVinci

    Tom St Denis Guest

    DaVinci wrote:
    > int main()
    > {
    > double d = 33.33;
    > int i = d;
    > return 0;
    > }
    >
    > Makefile:
    >
    > gcc -c -g -Wall -std=c99 test.c
    > but I can't get any warning information.
    > how can I get the warning on the type converation?


    use a C++ compiler :)

    That's not invalid C as far as I can tell. You can add -W [or now
    -Wextra] for more warnings though.

    Tom
    Tom St Denis, Oct 17, 2006
    #2
    1. Advertising

  3. DaVinci

    DaVinci Guest

    Tom St Denis wrote:
    > DaVinci wrote:
    > > int main()
    > > {
    > > double d = 33.33;
    > > int i = d;
    > > return 0;
    > > }
    > >
    > > Makefile:
    > >
    > > gcc -c -g -Wall -std=c99 test.c
    > > but I can't get any warning information.
    > > how can I get the warning on the type converation?

    >
    > use a C++ compiler :)


    what a pit.
    I used to waste a long time to debug a programme whose problem is just
    there.


    >
    > That's not invalid C as far as I can tell. You can add -W [or now
    > -Wextra] for more warnings though.
    >
    > Tom
    DaVinci, Oct 17, 2006
    #3
  4. DaVinci

    Tom St Denis Guest

    DaVinci wrote:
    > > use a C++ compiler :)

    >
    > what a pit.
    > I used to waste a long time to debug a programme whose problem is just
    > there.


    Write better code?

    If you can't keep track of your variables then choose names that
    represent their types, e.g.

    int iCounter;
    float fTotal;
    double dAverage;
    char cName[MAXSTR];

    etc...

    Otherwise, just be more careful and only use the types the problem
    requires.

    Tom
    Tom St Denis, Oct 17, 2006
    #4
  5. DaVinci

    Joe Wright Guest

    DaVinci wrote:
    > int main()
    > {
    > double d = 33.33;
    > int i = d;
    > return 0;
    > }
    >
    > Makefile:
    >
    > gcc -c -g -Wall -std=c99 test.c
    > but I can't get any warning information.
    > how can I get the warning on the type converation?
    >

    What warning?

    #include <stdio.h>
    int main(void)
    {
    double d = 33.33;
    int i = d;
    printf("%d\n", i);
    return 0;
    }

    Is perfectly valid C.

    --
    Joe Wright
    "Everything should be made as simple as possible, but not simpler."
    --- Albert Einstein ---
    Joe Wright, Oct 19, 2006
    #5
  6. Joe Wright <> writes:
    > DaVinci wrote:
    >> int main()
    >> {
    >> double d = 33.33;
    >> int i = d;
    >> return 0;
    >> }
    >> Makefile:
    >> gcc -c -g -Wall -std=c99 test.c
    >> but I can't get any warning information.
    >> how can I get the warning on the type converation?
    >>

    > What warning?
    >
    > #include <stdio.h>
    > int main(void)
    > {
    > double d = 33.33;
    > int i = d;
    > printf("%d\n", i);
    > return 0;
    > }
    >
    > Is perfectly valid C.


    Yes, which is why it would be a warning and not an error message (in a
    typical implementation; the standard, of course, makes no such
    distinction between different kinds of diagnostic messages).

    You might reasonably want a warning on implicit conversions that lose
    information, as this one does.

    The answer to the original question is: There is no mechanism in
    standard C to control which warnings will be issued. Try the gcc
    documentation; failing that, try gnu.gcc.help.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Oct 19, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pete Becker
    Replies:
    0
    Views:
    1,365
    Pete Becker
    Feb 10, 2005
  2. pkirk25
    Replies:
    5
    Views:
    432
    Chris Dollin
    Sep 27, 2006
  3. B. Williams

    warning C4267 and warning C4996

    B. Williams, Oct 26, 2006, in forum: C++
    Replies:
    17
    Views:
    2,613
  4. WARNING! Prosoftstore.com is a SCAM! WARNING!

    , Jul 8, 2007, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    304
  5. Julian Mehnle
    Replies:
    17
    Views:
    843
    Julian Mehnle
    May 18, 2006
Loading...

Share This Page