On 14/02/2011 13:59, Mickael Wolff wrote:
> On 12/02/11 19:52, Tomalak Geret'kal wrote:
>>> According to the standard, yes. But not according to
>>> reality: many
>>> compilers, g++ included, do not control the C library
>>> headers so
>>> <stddef.h> does not declare names in namespace std.
>>
>> namespace std {
>> #incude <stddef.h>
>> }
>
> This introduces a big issue if you try to use <cstddef> and
> <stddef.h> because of the headers safeguards. size_t should
> not be longer available in global namespace when including
> the legacy header.
>
According to C++, it's *not* a "legacy" header. It's
provided for backwards compatibility but is not a
cut-and-paste of the C library code (though it will be very
similar if not almost the same). In particular, any code
therein that uses language elements that are not backward
compatible from C++ to C will be different (e.g. you won't
find an argument name `new`, as this is a keyword in C++).
And, the .h headers are supposed to declare their contents
in both the global namespace *AND* namespace std.
Jonathan suggests that, unfortunately, this is not adhered
to in practice; I haven't checked it out but I trust the
source [:)] and this is very disturbing indeed. My
suggestion above to wrap an #include inside a namespace
declaration was, more than anything else, a joke. :)
> Have a look at the actual content of cstddef file :)
Whose cstddef file? Implementations vary across toolchains.
Tom