How can i define a global parameter which value is defined by a function

How can i define a global parameter which value is defined by a function

Hello! I want to ask a question about parameter.

Things start from IVF windows application, I want to define a Windows Message to communicate between process. So I use the function RegisterWindowMessage and add a piece of code to handle the message in the MainWndProc. However, according to MFC tradition, I add a case branch in the MainWndProc, but the case value must be a const. So I define the message to be global parameter in the ***global.f90, but i cannot do that. here is the statement in the ***global.f90

integer(UINT), parameter, public :: wm_Message = RegisterWindowMessage("083DDE42-5A00-4DAA-9C84-FAC23F8427D2")

obviously, it cannot be compiled. Because
1. fortran parameter cannot use the return value of a function as the value. But C++ could
2. module statement can not contain invoke function code.

How can i define a global parameter which value is defined by a function?

Thank you!

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

You can't do it this way. a PARAMETER constant is a compile-time constant.  What you want is a module variable that you set at the start of execution with the result of the function call.

Steve - Intel Developer Support

Hi Steve~

1.How can I define a module variable that I set at the start of execution with the result of the function call.

2. in c++, i can define a constant whose value defined by the start of execution with the result of the function call.

[c]

const UINT wm_Message = RegisterWindowMessage(_T("083DDE42-5A00-4DAA-9C84-FAC23F8427D2"));

[/c]

you mean I cannot do the same thing in Fortran?

Thank you!

Fortran does not have an equivalent of that C++ feature. Fortran allows only a "constant expression" when providing an initial value for a variable.

What I was suggestion was something like this:

module my_globals
use IFWINTY, only: UINT
implicit none
private
public :: wm_Message, initialize_globals
integer(UINT), PROTECTED :: wm_Message
contains
subroutine initialize_globals
use user32
! Initialize all global variables
wm_Message = RegisterWindowMessage("083DDE42-5A00-4DAA-9C84-FAC23F8427D2"C)
end subroutine initialize_globals
end module my_globals
...
program myprog
use my_globals
...
call initialize_globals
... rest of program

Any place you want to reference wm_Message you would need to add "use my_globals" to make it visible.

The public and private statements make sure that only the specific names listed in the public statement are visible to users of the module. The PROTECTED attribute prevents code outside the module from changing its value. You would add the call to initialize_globals at the start of the program.

Steve - Intel Developer Support

Leave a Comment

Please sign in to add a comment. Not a member? Join today