Why in some compilers if a function is not declared, the compilergives out a "warning" and not an "e

Discussion in 'C Programming' started by lostlander, Dec 9, 2007.

  1. lostlander

    lostlander Guest

    In ARMCC, and Microsoft C, when i use a function which is never
    defined or delared, it gives out a warning, not a compiling error?
    why?

    (This leads to a bug to my program since I seldom pay much attention
    to warnings...)

    Thanks for explanation!
    lostlander, Dec 9, 2007
    #1
    1. Advertising

  2. In article <>,
    lostlander <> wrote:

    >In ARMCC, and Microsoft C, when i use a function which is never
    >defined or delared, it gives out a warning, not a compiling error?
    >why?


    It might not matter, if it never gets called (which may of course
    depend on the input). I suppose it's a convenience to programmers
    building a system incrementally.

    >(This leads to a bug to my program since I seldom pay much attention
    >to warnings...)


    The flaw here doesn't seem to be in the compiler!

    -- Richard
    --
    :wq
    Richard Tobin, Dec 9, 2007
    #2
    1. Advertising

  3. lostlander

    Eric Sosman Guest

    lostlander wrote:
    > In ARMCC, and Microsoft C, when i use a function which is never
    > defined or delared, it gives out a warning, not a compiling error?
    > why?


    Under "C90" rules, and under "K&R" rules even before them,
    using an undeclared function is/was legal. The compiler assumes
    that the unknown function takes an unknown number of arguments of
    unknown types and returns an int value. If you write `f(42)' with
    no declaration of `f', the compiler acts as it would if you had
    previously written `int f();' as a declaration.

    Under "C99" rules it is an error to use an undeclared function.
    However, the Standard doesn't really distinguish between "errors"
    and "warnings" (except in the case of the #error directive), so
    the only real change is from "diagnostic optional" to "diagnostic
    required."

    > (This leads to a bug to my program since I seldom pay much attention
    > to warnings...)


    Trying for a Darwin Award, are you?

    --
    Eric Sosman
    lid
    Eric Sosman, Dec 9, 2007
    #3
  4. lostlander

    Jack Klein Guest

    Re: Why in some compilers if a function is not declared, the compiler gives out a "warning" and not an "error"??

    On Sun, 9 Dec 2007 03:05:57 -0800 (PST), lostlander
    <> wrote in comp.lang.c:

    > In ARMCC, and Microsoft C, when i use a function which is never
    > defined or delared, it gives out a warning, not a compiling error?
    > why?
    >
    > (This leads to a bug to my program since I seldom pay much attention
    > to warnings...)


    Please tell us your company's name so we can make a point of never
    buying anything they make.

    It you had worked for me, you wouldn't anymore.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://c-faq.com/
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
    Jack Klein, Dec 9, 2007
    #4
  5. lostlander

    Thad Smith Guest

    lostlander wrote:
    > In ARMCC, and Microsoft C, when i use a function which is never
    > defined or delared, it gives out a warning, not a compiling error?
    > why?
    >
    > (This leads to a bug to my program since I seldom pay much attention
    > to warnings...)


    C90 permits calls to undeclared functions. The linking process,
    however, usually generates an error if there are undefined references.
    Some linkers have an option to generate an executable file even through
    there are undefined references (called function doesn't exist). Are you
    getting an undefined reference error from your linker (translation phase 8)?

    --
    Thad
    Thad Smith, Dec 9, 2007
    #5
  6. Re: Why in some compilers if a function is not declared, the compiler gives out a "warning" and not an "error"??

    lostlander <> writes:
    > In ARMCC, and Microsoft C, when i use a function which is never
    > defined or delared, it gives out a warning, not a compiling error?
    > why?
    >
    > (This leads to a bug to my program since I seldom pay much attention
    > to warnings...)


    Start paying attention to warnings. They're there for a reason.

    Some warnings indicate serious problems in your code, even fatal
    errors. Other warnings might indicate something that the compiler
    isn't worried about, but that's actually ok (i.e., in some cases you
    might know better than the compiler). Understanding the difference is
    a substantial part of being a skilled C programmer.

    One clue: adding a cast just for the purpose of silencing a warning is
    practically never a good idea.

    If you see a warning that you don't understand, and attempts to
    understand it by reading your C reference materials and/or compiler
    documentation aren't helpful, this newsgroup is a good place to ask
    about it. Ideally, post a small complete program that exhibits the
    warning, and the text of the warning itself. Copy-and-paste the
    *exact* text both of the program and of the warning.

    --
    Keith Thompson (The_Other_Keith) <>
    Looking for software development work in the San Diego area.
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Dec 10, 2007
    #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. JohnZing

    declared or not declared ?

    JohnZing, Feb 5, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    1,584
    Jon Paal
    Feb 5, 2006
  2. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    878
    Mark Rae
    Dec 21, 2006
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,840
    Smokey Grindel
    Dec 2, 2006
  4. geletine

    commercial c compilers vs free c compilers

    geletine, Jul 2, 2006, in forum: C Programming
    Replies:
    33
    Views:
    1,313
  5. Jeff
    Replies:
    2
    Views:
    101
Loading...

Share This Page