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

L

lostlander

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!
 
R

Richard Tobin

lostlander said:
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
 
E

Eric Sosman

lostlander said:
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?
 
J

Jack Klein

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
 
T

Thad Smith

lostlander said:
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)?
 
K

Keith Thompson

lostlander said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top