## #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
 kinda a shot in the dark, but maybe ifndef = if not defined? like python
 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.

Recognitions:

## #ifndef statement in Fortran

 Quote by jf22901 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.

 Quote by AlephZero 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!

 Similar discussions for: #ifndef statement in Fortran Thread Forum Replies Engineering, Comp Sci, & Technology Homework 4 Programming & Comp Sci 17 Programming & Comp Sci 2 Programming & Comp Sci 1 Programming & Comp Sci 6