Fortran What is the purpose of #ifndef statements in Fortran code?

  • Thread starter Thread starter jf22901
  • Start date Start date
  • Tags Tags
    Fortran
AI Thread Summary
The discussion centers on the use of the #ifndef preprocessor directive in Fortran code, which is being processed through the C preprocessor. The #ifndef statement checks if a preprocessor variable, in this case "global," is not defined. If "global" is not defined, the code within the #ifndef block, such as defining an array, will be executed. It is clarified that "global" can be defined earlier in the code or passed to the compiler via a makefile with a flag like -Dglobal. The original poster discovers that their makefile includes this flag, confirming that the "global" variable is indeed defined, which affects the conditional compilation. The conversation emphasizes the importance of understanding the C preprocessor and reviewing makefile documentation for better clarity on this topic.
jf22901
Messages
55
Reaction score
1
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.
 
Technology news on Phys.org
kinda a shot in the dark,
but maybe ifndef = if not defined?
like python
 
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.
 
jf22901 said:
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.
 
AlephZero said:
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! :smile:
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Replies
20
Views
3K
Replies
14
Views
5K
Replies
5
Views
5K
Replies
4
Views
2K
Replies
16
Views
2K
Replies
8
Views
2K
Replies
4
Views
2K
Back
Top