TITLE: std lib headers and portability (Newsgroups: comp.std.c++, 1 Mar 2000) BOURGUIGNON: David Bourguignon > As a beginner, I need a piece of advice concerning portability of the > std lib headers. > > Let's take an example. I use two different compilers: > - on one hand, CC (SGI MIPSpro compiler) provides the std lib > header but do not provide the one ; > - on the other hand, g++ doesn't provide but do provide > . CLAMAGE: Steve Clamage The header is specific to C++. The header is inherited from the C library and has completely different content. The related C++ header is , not . BOURGUIGNON: > What is the best strategy to adopt when someone want to write portable > code with #include of the std lib headers? Just forget it and only use > good old C headers? CLAMAGE: C++ inherits the 18 standard C headers in their form. The C++ standard also specifies alternative versions. The latter versions put all the standard declarations only in the "std" namespace. The versions typically contain declarations other than those specified by the C and C++ standards. (For example, POSIX and XOpen specify additional content for some of those headers, and various operating systems typically add OS-specific declarations for historical reasons.) Whether these additional declarations appear in the headers, and whether those declarations are in namespace std, depends on the implementation. The C++ standard also specifies 32 additional headers that are unique to C++. These include what is informally known as the "STL", string classes, iostream classes, and miscellaneous runtime support declarations. These standard C++ headers do not have a form. Some C++ implementations provide .h versions of some of those 32 headers, but you can't depend on any particular content (because they are not standard). Since not all C++ implementations provide the versions of the 18 C headers, your code will be more portable if you use the forms. For the remaining 32 C++ headers, use the form for portability. If the implementation provides the C++ standard library at all, it will provide the headers. (Private Correspondence, 20 April 2000) TRIBBLE: David R Tribble [mailto:david@tribble.com] Unfortunately, use of the C++ headers has been deprecated (see Annex D, "Compatibility Features"), i.e., they are not guaranteed to be part of the C++ standard in future revisions. It's a catch-22; on the one hand, current C++ implementations haven't yet caught up with the C++98 standard, so you are safer using the C header names (), but on the other hand, future C++ implementations might not be required to support the C headers, so you are investing in the future by not using them. _______________________________________________ cpptips mailing list http://cpptips.hyperformix.com