Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 2 Mar 2005 19:17:52 +0200
From:      Giorgos Keramidas <keramida@ceid.upatras.gr>
To:        Florian Hengstberger <e0025265@student.tuwien.ac.at>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: c standard
Message-ID:  <20050302171752.GA5229@orion.daedalusnetworks.priv>
In-Reply-To: <icqfqw.8f29so@webmail.tuwien.ac.at>
References:  <icqfqw.8f29so@webmail.tuwien.ac.at>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2005-03-02 17:13, Florian Hengstberger <e0025265@student.tuwien.ac.at> wrote:
> Following is possible with gcc and g++:
>
> #include <math.h>
>
> double sin(double)
> {
>     return 1;
> }
>
> int main()
> {
>     sin(1);
>     return 1;
> }
>
> Why I don't get any warnings like:
>
> sin prevously defined in math.h ...
>
> when I compile with -Wall -pedantic -ansi.

Are you sure?  It fails to compile here:

$ cc -std=c89 -pedantic sin.c
sin.c: In function `sin':
sin.c:3: error: parameter name omitted

$ cc -std=c99 -pedantic sin.c
sin.c: In function `sin':
sin.c:3: error: parameter name omitted

> Why is it possible to overwrite the definition of sin, is this part of
> the standard?

There is no definition of sin() at that point.  Only a declaration
(i.e. a prototype of the function).  Your definition happens to match
the visible prototype, so it accepts your custom definition of sin().

> Secondly the definition (not declaration) of double sin(double) misses
> a variable!  Is this ok, when the variable is not referenced in the
> code?

This is not ok, as far as I can tell from the warnings above.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050302171752.GA5229>