New Reply

#ifndef statement in Fortran

 
Share Thread
Oct17-11, 03:49 AM   #1
 

#ifndef statement in Fortran


Hi all

I'm using Fortran code written by someone else, and a lot of the files have #ifndef statements in them. For example:

Code:
#ifndef global
      REAL array(2500)
#endif
I've tried searching online, but can't find anything useful that actually explains what this bit of code does. Can anyone on here offer any help? I'm assuming it only defines the array if some condition is met, but what condition?

Many thanks.
PhysOrg.com science news on PhysOrg.com

>> City-life changes blackbird personalities, study shows
>> Origins of 'The Hoff' crab revealed (w/ Video)
>> Older males make better fathers: Mature male beetles work harder, care less about female infidelity
Oct17-11, 04:57 AM   #2
 
kinda a shot in the dark,
but maybe ifndef = if not defined?
like python
Oct17-11, 05:51 AM   #3
D H
 
Mentor
The #ifdef and `#endif are C preprocessor statements. Your Fortran code apparently is being passed through the C preprocessor before being compiled as Fortran. Wikipedia article on the C preprocessor: http://en.wikipedia.org/wiki/C_preprocessor.
Oct17-11, 06:40 AM   #4

Math 2012
 
Recognitions:
Science Advisor Science Advisor

#ifndef statement in Fortran


Quote by jf22901 View Post
I'm assuming it only defines the array if some condition is met, but what condition?
The condition is that a preprocessor variable called "global" is not defined (and it's very unlikely that is defined by default).

It could be defined earlier in the source code with a statement like
#define global
or more likely it would be passed to the compiler from the makefile with an option like
-Dglobal
either in the makefile itself, or on the command line when you run make.

As DH said, see the documentation for the C preprocessor, and also for your version of make.
Oct17-11, 10:41 AM   #5
 
Quote by AlephZero View Post
The condition is that a preprocessor variable called "global" is not defined (and it's very unlikely that is defined by default).

It could be defined earlier in the source code with a statement like
#define global
or more likely it would be passed to the compiler from the makefile with an option like
-Dglobal
either in the makefile itself, or on the command line when you run make.

As DH said, see the documentation for the C preprocessor, and also for your version of make.
Thanks for the help everyone. I've just checked the makefile and it does indeed have a compiler flag with '-Dglobal'. I'd never noticed that before!

I'll go and check out all this preprocessor stuff in more detail. I don't know what I'd do without the helpful folks here at PF!
New Reply

Similar discussions for: #ifndef statement in Fortran
Thread Forum Replies
FORTRAN 77 read statement Engineering, Comp Sci, & Technology Homework 4
Goto statement, mostly regarding Fortran Programming & Comp Sci 17
FORTRAN Write Statement Issue Programming & Comp Sci 2
meaning for fortran statement Programming & Comp Sci 1
Fortran 90 very basic question : else if statement Programming & Comp Sci 6