C++ FAQ LITE and header files

T

Thomas Grund

Hi,

On the website

http://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.4

the following is written:

"The C++ standard library is guaranteed to have 18 standard headers from
the C language. These headers come in two standard flavors, <cxxx> and
<xxx.h> (where xxx is the basename of the header, such as stdio, stdlib,
etc). These two flavors are identical except the <cxxx> versions provide
their declarations in the std namespace only, and the <xxx.h> versions
make them available both in std namespace and in the global namespace."

Based on this the following code should compile but it does not with
several compilers (including Comeau):

#include <stdio.h>

int main()
{
std::printf("hallo\n");
}

Is it right that the statement should be that the <cxxx> versions provide
their declarations in the std namespace and the global namespace and the
<xxx.h> versions make them available in the global namespace only??

Thanks a lot,
Thomas
 
V

Victor Bazarov

Thomas said:
Hi,

On the website

http://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.4

the following is written:

"The C++ standard library is guaranteed to have 18 standard headers
from the C language. These headers come in two standard flavors,
<cxxx> and <xxx.h> (where xxx is the basename of the header, such as
stdio, stdlib, etc). These two flavors are identical except the
<cxxx> versions provide their declarations in the std namespace only,
and the <xxx.h> versions make them available both in std namespace
and in the global namespace."

Based on this the following code should compile but it does not with
several compilers (including Comeau):

#include <stdio.h>

int main()
{
std::printf("hallo\n");
}

Is it right that the statement should be that the <cxxx> versions
provide their declarations in the std namespace and the global
namespace and the <xxx.h> versions make them available in the global
namespace only??

Well, that's according to the current Standard. However, it's been
a stumbling point for many library implementors. Since it is not
really a serious detriment, the new Draft makes it unspecified whether
including the .h form puts names in 'std' (and, similarly, it's also
unspecified that including the c-form puts names in the global NS).

Once the new Standard is adopted, the FAQ will have to be amended to
reflect that, I guess.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top