Article View: comp.unix.programmer
Article #3540Re: g++ -ansi not recongizing stdlib's erand48
From: Jens.Toerring
Date: Tue, 18 Mar 2003 00:52
Date: Tue, 18 Mar 2003 00:52
37 lines
2748 bytes
2748 bytes
In comp.unix.programmer Fred Ma <fma@doe.carleton.ca> wrote:
> I've been advised to use "gcc -ansi" to maintain portable
> code. I have the following file erand.cpp (an example):
<snipped>
> I get the following compiler messages:
> $ g++ -c -ansi erand.cpp
> erand.cpp: In member function `double myrand::operator()()':
> erand.cpp:7: `erand48' undeclared (first use this function)
> erand.cpp:7: (Each undeclared identifier is reported only once for each
> function it appears in.)
> I understand that erand48 is not standard C, but doesn't it's
> appearance in stdlib *make* it defined? Why would it be
> treated any differently from any other prototype in any other
> include file? I did confirm that erand48 is in stdlib.
I don't know much about C++, but if this isn't too different from C
the problem is that by using -ansi you explicitely tell that you
want non-standard functions (like erand48()) *not* to be declared
in the header files (that's usually done by some #if's to exclude
these non-standard functions in case -ansi is used). You will have
to either supply your own declaration of erand48() or forgo using
the -ansi option. The -ansi option is for the cases where you want
to make really sure your program is portable by using only standard
functions (or when you want to post code in clc ;-), but if you need
non-standard functions you have to accept that it isn't, at least in
this respect.
Regards, Jens
--
_ _____ _____
| ||_ _||_ _| Jens.Toerring@physik.fu-berlin.de
_ | | | | | |
| |_| | | | | | http://www.physik.fu-berlin.de/~toerring
\___/ens|_|homs|_|oerring
Technical Details
Message-ID:
<b55qju$250d27$1@fu-berlin.de>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!fu-berlin.de!uni-berlin.de!crowley.physik.fu-berlin.DE!not-for-mailReferences:
<3E7665C2.B40DC681@doe.carleton.ca>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,39656fba4b7778f2
X-Google-Attributes: gid11318c,public
X-Google-Thread: fc89c,39656fba4b7778f2
X-Google-Attributes: gidfc89c,public
X-Google-ArrivalTime: 2003-03-17 16:52:15 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!fu-berlin.de!uni-berlin.de!crowley.physik.fu-berlin.DE!not-for-mail
From: Jens.Toerring@physik.fu-berlin.de
Newsgroups: comp.unix.programmer,gnu.gcc.help
Subject: Re: g++ -ansi not recongizing stdlib's erand48
Date: 18 Mar 2003 00:52:14 GMT
Organization: Freie Universitaet Berlin
Lines: 37
Sender: <jens@crowley.physik.fu-berlin.de>
Message-ID: <b55qju$250d27$1@fu-berlin.de>
References: <3E7665C2.B40DC681@doe.carleton.ca>
NNTP-Posting-Host: crowley.physik.fu-berlin.de (160.45.33.110)
X-Trace: fu-berlin.de 1047948734 72365127 160.45.33.110 (16 17 19)
X-Orig-Path: not-for-mail
User-Agent: tin/1.4.2-20000205 ("Possession") (UNIX) (Linux/2.4.16 (i686))