• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: On the use of namespaces to manage versions in C++
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: On the use of namespaces to manage versions in C++


  • Subject: Re: On the use of namespaces to manage versions in C++
  • From: Steve Checkoway <email@hidden>
  • Date: Sat, 3 Feb 2007 16:31:13 -0800


On Feb 2, 2007, at 4:15 PM, James Widman wrote:

I'm not sure if this is the right list, but it seems like subscribers here would likely be on the ADC news list, and I want speak up about one of the C++ "tips & tricks" listed in today's edition (ADC News #475). See here:

http://developer.apple.com/technotes/tn2007/tn2185.html#TNTAG14

I question the legitimacy of encouraging developers to use the strong namespace extension for two reasons:

1. The GCC documentation recommends against it; see here:
http://gcc.gnu.org/onlinedocs/gcc-4.1.1/gcc/Strong- Using.html#Strong-Using

A good reason, but then Apple's gcc used #import when it was deprecated in FSF gcc (a cursory glance at google tells me that it might be undeprecated after a patch from Apple).


2. We can get the same desired effects (namely, source compatibility while changing the mangled names of library symbols for each version) using only features from ISO C++98. Consider the following modified version of the example from the above article:
[snip]
Yes, it's more verbose on the library side, but for that minor cost you'll be able (or at least one step closer to being able) to use the code with any compiler that conforms to the ISO C++ Standard -- and not just GCC and the limited set of vendors that mimic GCC in this way. And if you're writing a library interface, odds are that's not something to be taken lightly.

Why not just follow what cxxabi.h does? Everything is in namespace __cxxabiv1 and then at the end of the header it has
namespace abi = __cxxabiv1;


If this ever changes, then older code will still link to the proper version. For example:

-- namespace.h --
namespace foov1 { void bar(); }
namespace foov2 { void bar(); }
#ifdef V2
namespace foo = foov2;
#else
namespace foo = foov1;
#endif

-- namespace.cc --
#include <cstdio>
#include "namespace.h"
void foov1::bar() { puts( "v1" ); }
void foov2::bar() { puts( "v2" ); }

-- n.cc --
#include "namespace.h"
int main() { foo::bar(); return 0; }

steve$ g++ -o namespace.o -c -Wall namespace.cc
steve$ nm namespace.o|grep ' T '
00000000 T __ZN5foov13barEv
0000003c T __ZN5foov23barEv
steve$ g++ -o n1 -Wall n.cc namespace.o
steve$ g++ -o n2 -Wall -DV2 n.cc namespace.o
steve$ ./n1
v1
steve$ ./n2
v2


-- Steve Checkoway



Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: On the use of namespaces to manage versions in C++
      • From: James Widman <email@hidden>
References: 
 >On the use of namespaces to manage versions in C++ (From: James Widman <email@hidden>)

  • Prev by Date: Re: Xcode dependency handling
  • Next by Date: Re: Automatic versioning
  • Previous by thread: On the use of namespaces to manage versions in C++
  • Next by thread: Re: On the use of namespaces to manage versions in C++
  • Index(es):
    • Date
    • Thread