Thread View: comp.unix.programmer
3 messages
3 total messages
Started by Fred Ma
Tue, 18 Mar 2003 00:18
g++ -ansi not recongizing stdlib's erand48
Author: Fred Ma
Date: Tue, 18 Mar 2003 00:18
Date: Tue, 18 Mar 2003 00:18
32 lines
2087 bytes
2087 bytes
Hi,
I've been advised to use "gcc -ansi" to maintain portable
code. I have the following file erand.cpp (an example):
#include <cstdlib>
#include <vector>
using namespace std;
struct myrand { public:
vector<unsigned short> xseed;
double operator()(void) { return erand48(&xseed[0]); };
};
myrand RndGenr;
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.
Thanks for any comments. I'm using gcc 3.2 on cygwin 1.3.20-1.
Fred
Re: g++ -ansi not recongizing stdlib's erand48
Author: 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
Re: g++ -ansi not recongizing stdlib's erand48
Author: Fred Ma
Date: Tue, 18 Mar 2003 07:08
Date: Tue, 18 Mar 2003 07:08
18 lines
2046 bytes
2046 bytes
Jens.Toerring@physik.fu-berlin.de wrote: > 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 Thanks for clarifying, Jens. And for all the assistance you've given. Fred
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads