__declspec(dllimport)

H

hsharsha

Consider the below code:

extern __declspec(dllimport) int myvariable;
template<const int *p>
class MyClass{
public:
static void myfunction(){
}
};

int main(void){
MyClass<&myvariable>::myfunction();
return 0;
}

"A dllimport variable is accessed indirectly through a variable and
therefore does not have a constant address". Is this statement valid /
correct ???
 
I

Ivan Vecerina

: Consider the below code:
:
: extern __declspec(dllimport) int myvariable;
: template<const int *p>
: class MyClass{
: public:
: static void myfunction(){
: }
: };
:
: int main(void){
: MyClass<&myvariable>::myfunction();
: return 0;
: }
:
: "A dllimport variable is accessed indirectly through a variable and
: therefore does not have a constant address". Is this statement valid /
: correct ???
It is certainly valid in a given context, in that the loaded DLL
may end-up storing the variable in any location.

But when instantiating a template, what matters is not the 'address'
of a variable, but its 'linkage': the "name" by which it will be
known to the linker, which typically is used to generate a mangled
name for the template instance.
When the compiler is being run, it has no idea anyway of the
storage address of the variable.

Ivan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top