Why in some compilers if a function is not declared, the compilergives out a "warning" and not an "error"?? - C

This is a discussion on Why in some compilers if a function is not declared, the compilergives out a "warning" and not an "error"?? - 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 ...

+ Reply to Thread
Results 1 to 6 of 6

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

  1. Default Why in some compilers if a function is not declared, the compilergives out a "warning" and not an "error"??

    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!

  2. Default Re: Why in some compilers if a function is not declared, the compilergives out a "warning" and not an "error"??

    In article <0b56ca9a-d285-4b9b-a531-3a276378fea8@s12g2000prg.googlegroups.com>,
    lostlander <lostlander.tom@gmail.com> 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

  3. Default Re: Why in some compilers if a function is not declared, the compilergives out a "warning" and not an "error"??

    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
    esosman@ieee-dot-org.invalid

  4. Default 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
    <lostlander.tom@gmail.com> 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

  5. Default Re: Why in some compilers if a function is not declared, the compilergives out a "warning" and not an "error"??

    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

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

    lostlander <lostlander.tom@gmail.com> 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) <kst-u@mib.org>
    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"

+ Reply to Thread

Similar Threads

  1. Replies: 8
    Last Post: 12-08-2007, 03:24 AM
  2. email-display: "N", "D", " ": yeah; but "O"? How to MARK "O"?
    By Application Development in forum Mutt
    Replies: 0
    Last Post: 10-30-2007, 07:13 AM
  3. Replies: 0
    Last Post: 03-21-2007, 01:26 PM
  4. """""""""""""""""""""Visual C++ 2005 Express"""""""""""""""""
    By Application Development in forum DOTNET
    Replies: 0
    Last Post: 03-12-2006, 03:55 AM
  5. Replies: 2
    Last Post: 08-11-2004, 02:00 AM