This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: problem with builtin functions



  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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]