In article <pnMLa.3624$>, Jim Fischer
<> wrote:
| Howard Hinnant wrote:
| > In article <bdn2gu$987$1$>, <>
| > wrote:
| >
| > The C++ standard says that size_t's full names is std::size_t. On
| > platforms where we control the C lib, we follow the standard on this.
| > I'm guessing size_t was available, but simply in namespace std. Your
| > fix (#include <stddef.h>) is a good way to go. This not only makes
| > sure std::size_t is available, it also imports it into the global
| > namespace, so you can access it without the std:: prefix. And such a
| > fix is very portable.
|
| I could be wrong on this, but my recollection is that names from the
| standard C library (e.g., size_t) are only introduced into C++'s 'std'
| namespace when the '<cname>' C++ headers are used. Furthermore, these
| '<cname>' headers also employ using-declarations to explicitly introduce
| the C library names (e.g., size_t) into the C++ app's global namespace.
| For example,
|
| #include <cstddef> // ISO C++ header
|
| The C++ header 'cstddef' introduces the name 'size_t' (for example) into
| C++'s 'std' namespace, and follows it with an explicit using-declaration
| (D5/3), i.e.,
|
| namespace std { typedef {whatever} size_t; }
| using std::size_t;
|
| Since the name 'size_t' is introduced into the global namespace by the
| using-declaration, the C++ program can simply specify 'size_t' and not
| 'std::size_t'. IIRC, this holds for most (but not all) "things" in the C
| library -- e.g., with <cstdio>, the C++ program can simply specify
| 'printf' and not 'std:

rintf':
|
| #include <cstdio>
| int main() {
| printf("Hello,World\n"); // OK
| }
|
|
| OTOH, C library names (e.g., 'size_t') are NOT introduced into the C++
| 'std' namespace when a C header is specified in a C++ translation unit:
|
| #include <stddef.h> /* ISO C header */
| // At this point, 'size_t' is NOT in the 'std' namespace
|
|
| The bottom line here is this: the unqualified name 'size_t' should be
| visible within the global namespace of a C++ program if either the C++
| header <cstddef> or the C header <stddef.h> is specified.
I believe you have it backwards according to the standard. However
your interpretation is fairly close to common practice.
From the C++ standard 17.4.1.2:
| -4- Except as noted in clauses lib.language.support through
| lib.input.output , the contents of each header cname shall be the same
| as that of the corresponding header name .h , as specified in ISO/IEC
| 9899:1990 Programming Languages C (Clause 7), or ISO/IEC:1990
| Programming Languages --- C AMENDMENT 1: C Integrity, (Clause 7), as
| appropriate, as if by inclusion. In the C++ Standard Library, however,
| the declarations and definitions (except for names which are defined as
| macros in C) are within namespace scope ( basic.scope.namespace ) of
| the namespace std.
| -7- depr.c.headers , Standard C library headers, describes the effects
| of using the name .h (C header) form in a C++ program.*
| [Footnote: The ".h" headers dump all their names into the global
| namespace, whereas the newer forms keep their names in namespace std .
| Therefore, the newer forms are the preferred forms for all uses except
| for C++ programs which are intended to be strictly compatible with C.
| --- end foonote]
--
Howard Hinnant
Metrowerks