Alf P. Steinbach wrote in news: in
comp.lang.c++:
>> What about export makes you think it won't work ?
>
> The reason I'm wondering was given in the next paragraph, cited below:
>
>
>> > Okay I don't have a compiler that supports 'export' so don't know
>> > much about it, but if it's able to compile templates separately
>> > then it seems that the _linker_ must detect the invalid
>> > static_cast.
>>
>> The "compilation" done by export is only half the "compilation" that
>> needs to be done. A compiler that implements export must do the
>> second half (instantiation) at _link_ time.
>
> By studying your answers below I think I see what's going on. It's
> not instantiation at _link_ time but instantiation that uses
> precompiled information. In other words, the compiler needs access to
> the compiled form of the template, not just the header file -- and
> if that's the case then 'export' seems to be a very limited feature.
>
Yes, I think it promises faster compile times, and also the exported
code that isn't in a header (the defenition's) gets protected from
#include order and #define issues, though both of these might affect
the specialization's found and overloads found by ADL.
> The alternative is that the linker invokes a partial compilation, or
> at least class hierarchy information, but below you answer "no" to
> that?
>
Well it can "precompile" any bits that are non-dependant, say:
// "exported.hpp"
export template < typename T > struct X
{
int foo();
T bar();
};
// EOF
// "exported.cpp"
#include "exported.hpp"
#include <string>
using namespace std;
int X< T >::foo()
{
return 1;
}
template < typename T >
T X< T >::bar()
{
return T( foo(), string( "bar" ) );
}
X< T >::foo() could be fully compiled, but X< T >::bar() would
need to be in some itermediate form.
However the call's to X< T >::foo() and
std::string::string( char const * ) would be fully resolved and fixed.
Also std::basic_string< char > (aka std::string) could be instantiated
(unless its also exported).
// "main.cpp"
#include <string>
struct string
{
string( char const * ) {}
};
struct Y
{
int ii;
std::string ss;
Y( int i, std::string s ) : ii( i ), ss( s ) {}
};
#include "exported.hpp"
int main()
{
X< Y > x( 0, "" );
X< Y > y( x.bar() );
}
AFAICT the compilation of "main.cpp" would have to export the
declaration's and defenition's of Y<>, so that the linker/compiler
could actually instantiate X< Y >.
Or maybe when compiling "main.cpp" the compiler would /import/
whatever was exported by compiling "exported.cpp":
14/9 [Note: an implementation may require that a translation
unit containing the definition of an exported template be compiled
before any translation unit containing an instantiation of that
template. ]
The more I type (into this post) the more I'm becoming convinced
that any compilation-speedups export might give us ara a *fragile*
thing at best

.
>
>> > So, is that detection required by the standard (if so, where), and
>> > are linkers really that smart?
>>
>> No the compiler (whenever it compiles) detects the errors:
>>
>> When the compiler instantiates the exported code it need's to
>> callback (if you like) to the main compile to get all the info' about
>> the paramiter types.
>
>
Rob. --
http://www.victim-prime.dsl.pipex.com/