This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


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

Re: STL headers problem


Ben Scherrey wrote:
> Gerald Pfeifer wrote:
> >
> > On Wed, 22 Jul 1998, Jordi de Antonio wrote:
> > > What's the difference between header files whit '.h' and without (p.e.
> > > <vector.h> and <vector>). I've always used '.h' one's, but now I'm
> > > having troube while porting the system to Visual C++ that doesn't have
> > > '.h' versions. I would like to know the difference before start to do
> > > changes.
> >
> > The headers without .h (e.g. <vector>) are the standard ones, while
> > those with .h (e.g., <vector.h>) are there mostly/only for backwards
> > compatibility.
> >
> > I'd recommend switching to the non-.h versions.
> 
> I've been watching this thread and haven't seen it mentioned but I seem
> to recall that there is another not-so-subtle difference between the
> <header> and <header.h> syntax. Don't the namespace aspects of C++ come
> into effect as a differentiating factor between the two? I thought that
> using the <header> syntax brought the headers into the std namespace
> whereas the <header.h> syntax brought them into the global space. This
> would imply that <header> syntax is the new, preferred method but that
> <header.h> would not necessarily be deprecated. Someone please confirm
> this or set me straight!

Here's the story:

The standard doesn't mention <vector.h> or <iostream.h>.  They may come with
the compiler, but their contents are entirely up to the compiler supplier.
They may put names in the global namespace, or in std::, or in katmandu::.
Of course if you use them your program is not portable.

It does mention the classical C headers, e.g. <stdio.h>.  Those will be there 
"forever" or until the next standard fails to mention them; after that their 
contents will be unconstrained by the standard (pretty much the status quo 
anyway, it seems.)  In the meantime, names in these headers are *supposed* to 
be in std:: but accessible from the global namespace too.  In practice they're 
just global in most releases, at the moment, and will be until everybody gets 
their shadow headers set up.

The standard defines non-.h versions of the C headers, e.g. <cstdio> and 
<cstring>, and its own headers e.g. <vector> and <iostream>.  Everything in 
these headers (except required macros: NULL, assert, errno, etc.) is supposed 
to be in std:: and only std::.  It's pretty important that this happen, because 
the standard library defines lots of names like "copy" and "find", which are 
also pretty common in user programs.

Current Egcs releases don't support namespaces, so standard conformance in this
area is kind of moot.  Egcs-1.1 will support namespaces, but the standard-conforming
library isn't ready yet, so the non-standard headers will have to do until it is.
Of course backward-compatibility headers <vector.h> etc. will still be available
when the conforming library is released.

If your code doesn't mention namespaces, you'll be better off using <vector.h>
than using <vector> today.  That way when the new libraries come out you will 
change a simple compiler flag to keep your code working; otherwise everything 
breaks.

Nathan Myers
ncm@cantrip.org


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