- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
[fortran]
integer(UINT), parameter, public :: wm_Message = RegisterWindowMessage("083DDE42-5A00-4DAA-9C84-FAC23F8427D2")
[/fortran]
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!
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
const UINT wm_Message = RegisterWindowMessage(_T("083DDE42-5A00-4DAA-9C84-FAC23F8427D2"));
you mean I cannot do the same thing in Fortran?
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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:
[fortran]
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
[/fortran]
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.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page