porting-howto II

Felix Natter fnatter@gmx.net
Sat Apr 29 13:39:00 GMT 2000


hi,

here is another version of the porting-howto.
(I post this to the list because it needs some more checking)

thanks,

--
Felix Natter

-- 
Sent through GMX FreeMail - http://www.gmx.net
Title: Libstdc++-porting-howto




  

  

  Porting to libstdc++-v3

  
  Namespaces std
  File-flags: ios::nocreate and
  ios::noreplace
  The new headers
  Iterator-changes
  Libc-macros
  Comments, suggestions, corrections, questions...
  

  
In the following, when I say portable, I will refer to "portable among ISO
14882-implementations". On the other hand, if I say "backportable" or
"conservative", I am talking about "compiles with older
libstdc++-implementations".


    
	Namespace std::
	
	  
The latest C++-standard (ISO-14882) requires that the standard C++-library
is defined in namespace std::. Thus, to use classes from the standard c++
library, you can do one of three things:
  
    wrap your code in namespace std { ... } => This is not an
   option because only symbols from the standard c++-library are defined in
   namespace std::.

    put a kind of using-declaration in your source (either
	using namespace std; or i.e. using std::string; )
	=> works well for source-files, but cannot be used in header-files

	use a fully qualified name for each libstdc++-symbol
	(i.e. std::string , std::cout ) => can always be used
  

      
Because there are many compilers which still use an implementation that
does not have the standard C++-library in namespace std:: , some
care is required to support these as well.

      
Namespace back-portability-issues are generally not a problem with g++,
because versions of g++ that do not have libstdc++ in std:: use
-fno-honor-std (ignore std:: , :: = std:: ) by
default. That is, the responsibility for enabling or disabling
std:: is on the user; the maintainer does not have to care about it.
This probably applies to some other compilers as well.

      
The following sections list some possible solutions to support compilers
that cannot ignore std::.
 
      
      Using namespace composition if the project uses a separate
      namespace
	  

	    
Gtk-- defines most of its
classes in namespace Gtk::. Thus, it was possible to adapt Gtk-- to
namespace std:: by using a C++-feature called namespace
composition . This is what happens if you put a
using -declaration into a namespace-definition: the imported
symbol(s) gets imported into the currently active namespace(s). For example:
namespace Gtk {
	using std::string;
	class Window { ... }
}


More information about the Libstdc++ mailing list