Boost logo

Boost :

From: Herve Bronnimann (hervebronnimann_at_[hidden])
Date: 2006-10-16 14:59:02


[Apologies for duplicates, I don't know if an earlier posting went through because I wasn't subscribed under this email address]
 
Dear boosters: According to the C++ standard, language linkage is part of the specification of a type and even though on many platforms two function types with different linkage specs (eg. C and C++ language linkage) are the same, the standard states rather unambiguously ([7.5 decl.link]) "Two function types with different language linkages are distinct types even if they are otherwise identical."

My question: does anyone know of a technique to determine the linkage of a function type at compile time? I'm not sure that that would matter for my purposes, but the question arose and I couldn't find an answer. Thanks for any feedback,
--Herve Bronnimann

PS: here's a concrete example of what I'm asking, a metafunction LinkageTraits that would make the following example compile (code obviously untested - all errors mine):

   #include <boost/static_assert.h>
   #include <boost/type_traits.h>

   struct CPPLinkageTag {};
   struct CLinkageTag {};

   extern "C" {
     typedef void functionWithCLinkageType();
   }
   typedef void functionWithCPPLinkageType();

   main()
   {
     BOOST_STATIC_ASSERT(
       boost::is_same<LinkageTraits<functionWithCLinkageType>::type,
                      CLinkageTag >::value
     );
     BOOST_STATIC_ASSERT(
       boost::is_same<LinkageTraits<functionWithCPPLinkageType>::type,
                      CPPLinkageTag >::value
     );
   }
 
 


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk