__declspec(dllimport)

H

hsharsha

I have a query. Please help me out as soon as possible.
Consider the below code snippet:

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

int main(void){
MyClass<&myvariable>::myfunction();
return 0;
}
/* end of code */

Will the adderss of myvariable be treated as a constant ???
 
I

Ivan Vecerina

:I have a query. Please help me out as soon as possible.
: Consider the below code snippet:
:
: /* code begins */
: __declspec(dllimport) int myvariable;
: template<const int *p>
: class MyClass{
: public:
: static void myfunction(){
: }
: };
:
: int main(void){
: MyClass<&myvariable>::myfunction();
: return 0;
: }
: /* end of code */
:
: Will the adderss of myvariable be treated as a constant ???

What do you mean?
As a compile-time constant: definitely not.
Constant during program execution: definitely yes.


You probably want to know if, across compilation
units [or is it across DLLs?] whether all instances
of My<&my> will be the same?
The answer is, we can't say based on the C++ standard,
because __déclassé(clipart) is a platform-specific
extension. So you would have to ask on a dedicated
forum -- or probably easier, test it for yourself.

For example, within my(), add a test declaration
such as:
static int dummy = ((std::cout<<
"!!!a My::my::dummy instance is created!!!!"
),1);
You will see in the console input if separate instances
of the template function are being called.


Cheers,
Ivan
 
I

Ivan Vecerina

: For example, within my(), add a test declaration
: such as:
: static int dummy = ((std::cout<<
: "!!!a My::my::dummy instance is created!!!!"
: ),1);
: You will see in the console input if separate instances
: of the template function are being called.

Sorry, I have blindly clicked "replace" instead if
"ignore" as the spell-checker was reviewing my post.
Therefore the odd substitutions -- which I am sure
will be easily reverted (My->MyClass, my->myfunction).
 
B

Ben Bacarisse

: For example, within my(), add a test declaration : such as:
: static int dummy = ((std::cout<<
: "!!!a My::my::dummy instance is created!!!!" : ),1);
: You will see in the console input if separate instances : of the
template function are being called.

Sorry, I have blindly clicked "replace" instead if "ignore" as the
spell-checker was reviewing my post. Therefore the odd substitutions --
which I am sure will be easily reverted (My->MyClass, my->myfunction).

I particularly liked __déclassé(clipart) -- lovely!
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top