Boost logo

Boost :

Subject: Re: [boost] C++03 / C++11 compatibility question for compiled libraries
From: Peter Dimov (lists_at_[hidden])
Date: 2018-02-10 17:13:46


Andrey Semashev wrote:
> On 02/10/18 18:43, Peter Dimov via Boost wrote:
> >
> > But, if you really wanted to know, libstdc++ in a situation like the
> > above (when the function has to be virtual because it's f.ex. specified
> > that way by the standard) does something like the following:
> >
> > #if cpp11
> >
> > virtual int __f( boost::function<int ()> const& F ) = 0;
> > virtual int f( std::function<int ()> const& F ) = 0;
> >
> > #else
> >
> > virtual int f( boost::function<int ()> const& F ) = 0;
> > virtual int __f( std::function<int ()> const& F ) = 0;
> >
> > #endif
> >
> > except of course we don't have std::function in C++03 mode, so even
> > declaring __f will be a problem.
>
> If you rely on the particular algorithm of vftable slot allocation,

I've never heard of a vtable slot allocation algorithm that is not the
particular one that everyone uses.

> declaring is not a problem - you can declare pretty much whatever virtual
> function. It's not going to be called anyway and its sole purpose is to
> reserve a particular slot.

It is going to be called, when a C++11 exe calls a C++03 library. It's true
that you can declare whatever you want (within limits - the calling
convention must stay the same), but you can't use it because it's not going
to be whatever you declared, it's going to be std::function.


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