Boost logo

Boost :

From: John Maddock (john_at_[hidden])
Date: 2006-10-17 08:31:42

Herve Bronnimann wrote:
> [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]) "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

I think it's not easy.

In the past I've tried creating partial-specialisations on the linkage type,
but it didn't work :-( This could be fixed with more recent compilers

Overload resolution does work up to a point:

typdef extern "C" int (cp*)(int);

true_type is_c_linkage(cp);
false_type is_c_linkage(int (*)(int));

But the problem is you can't declare something like:

template<class R, class T>
true_type is_c_linkage(extern "C" R(*)(T));

so you can't write a more generic solution :-(

You could try:

template <class F>
struct is_c_linkage : public mpl::false_{};

extern "C" {

template <class R, class T>
struct is_c_linkage<R(*)(T)> : public mpl::true_{};


and see if it works or not (obviously only on a compiler that differentiates
between C and C++ linkage).



Boost list run by bdawes at, gregod at, cpdaniel at, john at