Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Why in some compilers if a function is not declared, the compilergives out a "warning" and not an "error"??

Reply
Thread Tools

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

 
 
lostlander
Guest
Posts: n/a
 
      12-09-2007
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!
 
Reply With Quote
 
 
 
 
Richard Tobin
Guest
Posts: n/a
 
      12-09-2007
In article <0b56ca9a-d285-4b9b-a531->,
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
 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      12-09-2007
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
 
Reply With Quote
 
Jack Klein
Guest
Posts: n/a
 
      12-09-2007
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
 
Reply With Quote
 
Thad Smith
Guest
Posts: n/a
 
      12-09-2007
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 ?

--
Thad
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      12-10-2007
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) <kst->
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 With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
commercial c compilers vs free c compilers geletine C Programming 33 07-07-2006 05:21 AM
Why compilers do not "p = NULL" automatically after programs do "delete p"? gary C++ 13 11-05-2005 12:27 AM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57