www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/06/19/00:41:37

Date: Wed, 19 Jun 1996 07:38:54 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Erik Max Francis <max AT alcyone DOT com>
Cc: djgpp AT delorie DOT com
Subject: Re: Random numbers ...
In-Reply-To: <31C6B9D7.22A82DEE@alcyone.com>
Message-Id: <Pine.SUN.3.91.960619072122.17856B-100000@is>
Mime-Version: 1.0

On Tue, 18 Jun 1996, Erik Max Francis wrote:

> Pretty simple solution:  random is not an ANSI C function and is not available
> in any DJGPP libraries.

`random' indeed is non-ANSI, but DJGPP v2 *does* have it.  Please, people,
before you post such easy-to-verify statements, take a second and look
into libc.inf index. 

> Johan De Messemaeker wrote:
>
> > I'm trying to port my old Borland-progs to the DJGPP compiler.
> > But  there's a line i can't figure out :
> >
> >         int tmp;
> >         tmp = random(3);
> >
> > With Borland, no problemo, it compiles, with DJGPP version 2, nope ...

The reason that the code above won't compile with DJGPP is that `random', 
being a non-standard function, does different things in BC and DJGPP: in 
BC random(3) returns a random integer between 0 and 3, whereas in DJGPP 
`random' doesn't expect to get any parameters and always returns a random 
number in the 0..MAXINT range.  So GCC sees its prototype in <stdlib.h> 
saying this:

	long random(void);

and refuses to compile the above code.

Btw, it's always better to post the error message(s) that GCC prints when
you say ``the code won't compile'', because sometimes it's very hard to
guess what that message might be without actually recompiling the
fragment. 

- Raw text -


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