- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hey,
I am currently debugging my code for a runtime error (invalid pointer) but the compiler does not give me valuable information for locating this error even with -traceback. I am therefore make use of all the debug flags I found online with the hope that it may solve the problem:
FLAGS = -O2 -stand f03 -std -check all -traceback -warn all -fstack-protector -assume protect_parens -implicitnone
Using these flags, I actually get a lot more error than the one I had to begin with. One of them is about a variable name which does not have a type:
visc.f90(29): error #6404: This name does not have a type, and must have an explicit type. [BC_UY]
CALL FxxSBP_t (d2udy(i,:,k),u(i,:,k),h(2),nptsy, BC_UY)
The variable BC_UY is defined in a header file and loaded in the code with the #INCLUDE statement. Is there a way I can load in the variable from the header files so that the compiler initializes it correctly?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The #include is a preprocessor statement, not a Fortran statement. Fortran also has an INCLUDE statement. These are not equivalent. Either may be used provided you understand what is happening.
When using the Fortran preprocessor the #include works like it does with the C preprocessor.
The text is inserted into the file (source or other #include) at the position of the #include. *** Any #define that reside within the #include file are defined through the remainder of the compilation unit.
This said, any Fortran variables defined within the #include file are defined within the scope of the Fortran routine where the #include was positioned.
Where are you placing your #include statement?
What are your requirements for BC_UY?
What is the scope of BC_UY? (global, local, module)
You say "so that the compiler initializes it correctly", please clarify.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Jim,
My #INCLUDE statement is placed at the top of the file, before the MODULE is declared. I expect my BC_UY variable to be referred to only inside the module.
Here is my issue: the code I'm using (I only added bits of it, didn't write it all myself) works fine when I do not use the debug flags, but when I do, I get the error showed in my original post. I want to keep using BC_UY from the header files (load in with #INCLUDE) and not get a compile error. This error is not the one I was originally looking for, but since it is fatal, my compiler terminates after it.
Solal Amouyal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Fortran name scope is not the same as C/C++ name scope.
If you have included the file that declares BC_UY before the MODULE is opened, then it is NOT defined inside that module.
If you need it declared inside the module, move the #include statement to inside the module.
--Lorri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Also note:
If your module contains an #include file, in which the #include-'d file contains a
#define BC_UY 12345
The macro BC_UY only lives for the duration of the compilation unit from the #define through the end of file (or #undef BC_UY)
Subsequent to compiling the module containing the #define BC_UY 12345 if you were to then use
subroutine foo
USE YourModuleContaining_BC_UY
Then the macro BC_UY is not defined.
USE is not equivalent to #INCLUDE
Jim Dempsey

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