delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/11/11/10:04:44

Date: Tue, 11 Nov 1997 17:03:00 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Ove Kaaven <ovek AT arcticnet DOT no>
cc: djgpp AT delorie DOT com
Subject: Re: rand() or random()
In-Reply-To: <3466e64d.9875734@news.arcticnet.no>
Message-ID: <Pine.SUN.3.91.971111165750.17425H-100000@is>
MIME-Version: 1.0

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019