c standard

Giorgos Keramidas keramida at ceid.upatras.gr
Wed Mar 2 09:17:56 PST 2005


On 2005-03-02 17:13, Florian Hengstberger <e0025265 at 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.



More information about the freebsd-questions mailing list