On Jul 7, 6:06Â*pm, santosh <santosh....@gmail.comwrote:
user923005 wrote:
On Jul 6, 6:54�pm, CBFalconer <cbfalco...@yahoo.comwrote:
void main wrote:
Keith Thompson wrote:
void main <nos...@nospam.invalidwrites:
>When porting a program to MS-Windows I got a redefinition error
on "frand" (already defined in stdlib.h).
>Is it legal if I use "frand" in a source file if stlib.h is not
included there?
Yes.
There is no standard C function called "frand". �(There are
functions "rand" and "srand").
If a compiler, invoked in conforming mode, complains about you
defining a function called "frand", that's a flaw in the compiler.
I suggest you submit a bug report.
If you're invoking the compiler in non-conforming mode, then you
probably have no grounds for complaint, though you're free to
complain anyway.
Thanks but I need a really portable solution. I solved it like this
#define frand xyz
#include <stdlib.h>
#undef frand
Is that good practice?
No. �If the compiler writer has ignored the standard, you haveno
idea why and what is affected. �A better temporary step is to
replace *your* use of frand by something else. �And you shouldmake
loud and insistent bug reports to the compiler marketer and insist
the bug be fixed.
There is no frand() in any of the Microsoft standard headers. Â*E.g..:
C:\Program Files (x86)\Microsoft Visual Studio 8\VC\include>c:\utils
\grep.exe frand *.h
C:\Program Files (x86)\Microsoft Visual Studio 8\VC\include>
The fact that his name is "void main" just might possibly be a clue
that this is a troll.
Regardless of whether he is a troll his post is, as far as I can tell,
quite genuine. The identifier 'frand' *is* defined by a compiler in
stdlib.h, even under switches for disallowing all language extensions
and supposedly conforming to ANSI C.
I will not name the compiler in question, since it may be obvious to
more than a few already.
You certainly got me curious:
None in dev-cpp:
c:\dannfast\Dev-Cpp\include>grepcarl frand *.h
c:\dannfast\Dev-Cpp\include>
None in mingw:
c:\dcorbit64\mingw\include>grepcarl frand *.h
c:\dcorbit64\mingw\include>
None in Borland:
c:\dannfast\Borland\BCC55\Include>grepcarl frand *.h
sqlfront.h ( 586): #define SQLCRSFRAND 10088
wininet.h ( 3128): IN BOOL fRandomRead,
wininet.h ( 3138): IN BOOL fRandomRead,
c:\dannfast\Borland\BCC55\Include>
None in Watcom:
c:\dannfast\e_drive\watcom\h>grepcarl frand *.h
c:\dannfast\e_drive\watcom\h>
c:\dannfast\e_drive\watcom\qh>grepcarl frand *.h
c:\dannfast\e_drive\watcom\qh>
None in Digital Mars:
c:\dannfast\e_drive\dm\include>grepcarl frand *.h
c:\dannfast\e_drive\dm\include>
None in uClibc
c:\dannfast\e_drive\uClibc\include>grepcarl frand *.h
c:\dannfast\e_drive\uClibc\include>
None in Bloodshed:
c:\dannfast\e_drive\bloodshed\include>grepcarl frand *.h
c:\dannfast\e_drive\bloodshed\include>
None in Visual C++ 6.0:
c:\dannfast\lang\VC98\Include>grepcarl frand *.h
SQLFRONT.H ( 579): #define SQLCRSFRAND 10088
WININET.H ( 2696): IN BOOL fRandomRead,
WININET.H ( 2706): IN BOOL fRandomRead,
c:\dannfast\lang\VC98\Include>
None in VC++ 98:
c:\dcorbit64\Program Files\Microsoft Visual Studio
\VC98\Include>grepcarl frand *.h
SQLFRONT.H ( 579): #define SQLCRSFRAND 10088
WININET.H ( 2696): IN BOOL fRandomRead,
WININET.H ( 2706): IN BOOL fRandomRead,
c:\dcorbit64\Program Files\Microsoft Visual Studio\VC98\Include>
None in Visual Studio.Net:
c:\dannfast\Program Files\Microsoft Visual Studio .NET
\Vc7\include>grepcarl frand *.h
c:\dannfast\Program Files\Microsoft Visual Studio .NET\Vc7\include>
None in Visual Studio.Net 2003:
c:\dannfast\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include>grepcarl frand *.h
c:\dannfast\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include>
None in VC++ 8:
c:\dannfast\Program Files\Microsoft Visual Studio 8\VC
\include>grepcarl frand *.h
c:\dannfast\Program Files\Microsoft Visual Studio 8\VC\include>
None in VC++ 9:
c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include>grepcarl
frand *.h
c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include>
None in Clib:
c:\dannfast\e_drive\clib\compiler>grepcarl frand *.h
c:\dannfast\e_drive\clib\compiler>
None in SAS/C:
c:\dannfast\Program Files\SAS Institute\SASC701\include>grepcarl frand
*.h
c:\dannfast\Program Files\SAS Institute\SASC701\include>
None in Cint:
c:\dannfast\e_drive\root\cint\include>grepcarl frand *.h
c:\dannfast\e_drive\root\cint\include>
None in Tendra:
c:\dannfast\e_drive\tendra-20041231\src\lib\apis\ansi>grepcarl frand
*.h
c:\dannfast\e_drive\tendra-20041231\src\lib\apis\ansi>
Looks like LCC:
c:\dcorbit64\lcc\include>grepcarl frand *.h
stdlib.h ( 77): double frand(void);
wininet.h ( 1780): BOOL fRandomRead,
wininet.h ( 1787): BOOL fRandomRead,
xlcall.h ( 173): #define xlfRand 63
Suggestion to Jacob:
#ifndef __ANSIC__ONLY__
double frand(void);
#endif