Mail Archives: djgpp/1997/11/11/10:04:44
On Mon, 10 Nov 1997, Ove Kaaven wrote:
> Well, those copyright issues seem somewhat confusing.
> Let's see... how legal is this implementation?
>
> int rand(void)
> {
> return random();
> }
This is perfectly legal, but it breaks the ANSI Standard ruling that a
standard C library is not allowed to use any global symbols except those
reserved by the standard functions. In the case above, if an
ANSI-standard program will call `rand', it will pull `random' from the
library. This might mean grave problems and subtle bugs if that program
defines its own function named `random'. The bugs will be even more
subtle and catastrophic if the program defines a global variable named
`random' (the linker will bravely resolve them both to the same address).
Bottom line: an ANSI function cannot call non-ANSI functions unless
their names begin with an underscore (ANSI explicitly reserves all such
names in the global scope, so an application should not use them).
- Raw text -