A dllimport variable is accessed indirectly through a variable

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 ???
 
J

Jack Klein

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 ???

C++ does not have "dllimport" variables, making your question
off-topic here. DLLs are a mechanism of your operating, supported by
non-standard extensions of your compiler.

You need to ask this in a group like
or one of Microsoft's support
groups in the family.
 
M

Marek Vondrak

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

Partially. Access to an imported variable is implemented through an
indirection via the import address table (IAT), so the following code...

__declspec(dllimport) int myvariable;
int void f() { return myvariable; }
int * void g() { return &myvariable; }

....gets effectively translated into this:

int * const myvariable_ptr;
int void f() { return *myvariable_ptr; }
int * void g() { return myvariable_ptr; }

where the content of myvariable_ptr is filled by the image loader
(&myvariable_ptr is the address of the myvariable import entry in the IAT
table).

-- Marek
 

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

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top