This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: problem with builtin functions
- To: Haj dot Ten dot Brugge at net dot HCC dot nl, Jason Merrill <jason at cygnus dot com>
- Subject: Re: problem with builtin functions
- From: Mark Mitchell <mark at codesourcery dot com>
- Date: Wed, 15 Sep 1999 11:02:20 -0700
- Cc: egcs-bugs at egcs dot cygnus dot com
- Organization: CodeSourcery, LLC
- References: <199909150658.HAA11592@net.HCC.nl>
Hello,
I have a problem with builtin functions for the c++ compiler. When I compile
the next program:
typedef unsigned int size_t;
static inline int memcmp(const void *mem1, const void *mem2, size_t length)
{
const char *r1 = (const char *)mem1 - 1;
const char *r2 = (const char *)mem2 - 1;
for(;;)
if ( --length == (size_t)-1 ) break;
else if ( *++r1 != *++r2 ) return *r1 - *r2;
return 0;
}
The problem is that it defines the function memcmp as global.
Cute. The problem is that this code should be flagged as erroneous.
Basically, when you don't say -fno-builtin it's as if you said:
extern "C" int strlen (const char *);
extern "C" ...
for all the builtin functions at the top of every translation unit.
(With the new library, these builtins should really end up in `std',
but they don't, yet.) It turns out to be a lot of work to get the
compiler to really allow you to redefine these functions as as
non-extern "C" functions. (For instance, the name of your function
should be mangled; the compiler doesn't want to do this.)
It's much simpler, and more consistent, just to make your code an
error unless you use -fno-builtin. I'll check in a patch soon, and
wait to see if Jason disagrees with me. :-)
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com