c standard

Andrea Venturoli ml at netfence.it
Wed Mar 2 08:34:33 PST 2005


Florian Hengstberger wrote:

We are OT, anyway...



> Following is possible with gcc and g++:

These are two quite different cases: gcc is normally for C, g++ for C++. 
Contrary to what many people believe, they are two very different languages.



> #include <math.h>

If you are using C++ you should not #include <math.h>, but #include <cmath>



> double sin(double)
> {
>  return 1;
> }
> 
> Why I don't get any warnings like:
> sin prevously defined in math.h ...

Mainly because it isn't. In math.h (or cmath) sin is only declared, not 
defined.
There might possibly be other reasons: like the fact that in C++, 
provided you correctly included <cmath> and not <math.h>, the standard 
sin will be in namespace std, not in the global one.



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

Again, you are providing *a* definition; there is no previous one at 
this point to override.



> Secondly the definition (not declaration) of double sin(double)
> misses a variable!

You are not missing any variable; you are merely not assigning it any name.


 > Is this ok, when the variable is not referenced in the code?

Exactly.



  bye
	av.


More information about the freebsd-questions mailing list