This is the mail archive of the libstdc++@sourceware.cygnus.com mailing list for the libstdc++ project.


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

gcc builtin functions, e.g. memcpy, and namespace std


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

GCC defines some builtin functions for simple operations, such as
memcpy and strlen.

In C++, these should be in namespace std. However, defining a copy in
namespace std leads to the possibility of a compilation error

#include <cstring>

using namespace std;

int main()
{
  char buf1[50]="hello";
  char buf2[50];

  memcpy(buf2,buf1,50);
}

error - ambiguous use of memcpy
candidates are std::memcpy
<internal> memcpy

I have two suggestions:

1. Disable these builtins for C++, since they can be defined as
inlines in the headers anyway, by making -fno-builtin default for C++
2. Put them in namespace std:: when compiling C++, so they work just
as for C - silently being used instead of the library version where
possible

The third alternative, which is to force users to specify ::memcpy or
std::memcpy is not pleasant.

Anthonyc

PGP Fingerprint: 
0E2D D32A 8732 DC31 804C  D435 9BF0 F8FE 1C1B 9AD5
PGP Key at: http://i3.yimg.com/3/c7e5ee24/g/68fc2307.asc

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.1 for non-commercial use <http://www.pgp.com>
Comment: PGP Key at: http://i3.yimg.com/3/c7e5ee24/g/68fc2307.asc

iQA/AwUBOSPYH5vw+P4cG5rVEQLG5gCeLsvyNu2Nw/HOVvNkEVGLKpudhbAAn2BM
+bDm6EUTL4S/QcGdDblhRmZY
=vu94
-----END PGP SIGNATURE-----



__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com

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