Why strcpy and not strtod?

Maurizio Loreti loreti@pd.infn.it
Mon May 28 03:32:00 GMT 2001


I am experimenting with the 3.0 prerelease files, and I had to make small
changes to some of my C++ files in order to have them compiled.

One of these changes is to qualify some procedures from the C standard
library with the scope resolution operator: e.g. std::strcpy (after having
included <cstring>) is accepted, and an unqualified strcpy is not
accepted.  This is coherent with ISO/IEC 14882-1998: the names from the C
library header files MUST be in the namespace std (UNLESS they are defined
as a macro).

What I do not understand is why strtod is accepted (after having included
<cstdlib>).  Stepping in the following program with the debugger:

#include <cstdlib>
#include <cstring>

int main() {
  char abc[] = "abc", def[] = "def", pig[] = "3.14159265";
  double pi = strtod(pig, 0);
  std::strcpy(abc, def);
  return 0;
}

shows that strtod and strcpy are BOTH calls to functions and not macro
replacements:

....
6         double pi = strtod(pig, 0);
(gdb) s
strtod (__nptr=0xbffff8f0 "3.14159265", __endptr=0x0)
    at /usr/include/stdlib.h:245
245       return __strtod_internal (__nptr, __endptr, 0);
(gdb) n
246     }
(gdb) n
main () at foo.cxx:7
7         std::strcpy(abc, def);
(gdb) s
_ZSt6strcpyPcPKc (__s1=0xbffff90c "abc", __s2=0xbffff908 "def")
    at /usr/local/gcc/include/g++-v3/bits/std_cstring.h:104
104       { return __builtin_strcpy(__s1, __s2); }
(gdb)

So - why is strcpy and strtod is not in namespace std?

-- 
Maurizio Loreti                         http://www.pd.infn.it/~loreti/mlo.html
Univ. of Padova, Dept. of Physics - Padova, Italy            loreti@pd.infn.it

The instructions said to use Windows 98 or better - so I installed FreeBSD.



More information about the Gcc mailing list