Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Parameters and DLLs

OP1
New Contributor III
689 Views
I want to create a DLL which contains data to be shared between programs. I do not, however, want the calling units be able to change the content of my DLL data. How do I do this?

For instance, the following will create my DLL and the import *.lib library; but the integerI can be changed by the units referring to this DLL.

[fortran]MODULE MODULE_DLL
IMPLICIT NONE
!DEC$ ATTRIBUTES DLLEXPORT :: I
INTEGER :: I = 10
END MODULE MODULE_DLL[/fortran]

Now, if I declare the integerI as a parameter, the *.lib is not generated.

How can I protect my DLL data?

Thanks,

Olivier
0 Kudos
4 Replies
Les_Neilson
Valued Contributor II
689 Views
Don't export the variable. Instead export a function/subroutine which "gets" the value of the variable.

Les
0 Kudos
Steven_L_Intel1
Employee
689 Views
A parameter is not a variable - it is a "named constant". As such, it has no physical representation and cannot be exported or even linked against statically.

I agree that it seems that access routines are what is needed here. Fortran doesn't have the equivalent of C's "const" attribute, though if access to the variable is through a module you can give it the PROTECTED attribute and the compiler will generally disallow assignments from outside the module.
0 Kudos
OP1
New Contributor III
689 Views

Thanks Steve,

So, I'll guess I will just write an access routine. In this case, my question is the following: is there any CPU time penalty associated with a DLL function call?

For instance, assume that my DLL contains the function PI, defined as:

REAL(KIND=DP) FUNCTION PI
PI = 4.0_DP*ATAN(1.0_DP)
END FUNCTION PI

Now, in the unit calling this DLL, is suppose I can treat this function as if it were a variable in the unit scope:

A = 2.0_DP*PI
CALL ANOTHER_SUB(PI,SOME_OTHER_ARGUMENT)

Will this be efficient though? If not, I guess I can import all required constants/data at the beginning of my code and store them in a module used by my code subroutines.

Olivier

0 Kudos
Steven_L_Intel1
Employee
689 Views
You have to treat it as a function call, not a variable. In other words, PI(), not just PI.

If these are truly constants, then declare them as PARAMETER constants in a module and USE the module. Then those constants will be visible and it won't matter if you're using a DLL or not.
0 Kudos
Reply