C Preprocessor: Difference between revisions
From WikiROMS
Jump to navigationJump to search
No edit summary (change visibility) |
No edit summary (change visibility) |
||
Line 2: | Line 2: | ||
insert files into the code, and select relevant parts of the code depending on its | insert files into the code, and select relevant parts of the code depending on its | ||
directives. | directives. | ||
==Preprocesor Directives:== | |||
* The <span class="blue">#define</span> directive associates a symbolic name with some text. The preprocessor will replace the symbolic name with the specified text everywhere in the code. For example, | |||
:<span class="blue">#define</span> <span class="red">PRIVATE_2D_SCRATCH_ARRAY</span> Istr-3:Iend+3,Jstr-3:Jend+3 | |||
:is used to set the dimensions of private automatic 2D arrays. | |||
* The <span class="blue">#include</span> directive allows to insert the contents of another file into the source code. For Example: | |||
:<span class="blue">#include</span> <span class="red">"set_bounds.h"</span> | |||
:is used to insert the tile-bounds header file that computes the horizontal subdomain indices for RHO-, U- and V-type variables. | |||
* The <span class="blue">#ifdef, #endif</span> directive allows to control whether the preprocessor omits and includes part of the source code. For Example: | |||
:<span class="blue">#ifdef</span> <span class="red">[[PROFILE]]</span> | |||
::CALL wclock_on (ng, iNLM, 13) | |||
:<span class="blue">#endif</span> | |||
:is used to activate time profiling during execution. |
Revision as of 21:57, 31 October 2006
ROMS extensively uses C-preprocessing during compilation to replace code statements, insert files into the code, and select relevant parts of the code depending on its directives.
Preprocesor Directives:
- The #define directive associates a symbolic name with some text. The preprocessor will replace the symbolic name with the specified text everywhere in the code. For example,
- #define PRIVATE_2D_SCRATCH_ARRAY Istr-3:Iend+3,Jstr-3:Jend+3
- is used to set the dimensions of private automatic 2D arrays.
- The #include directive allows to insert the contents of another file into the source code. For Example:
- #include "set_bounds.h"
- is used to insert the tile-bounds header file that computes the horizontal subdomain indices for RHO-, U- and V-type variables.
- The #ifdef, #endif directive allows to control whether the preprocessor omits and includes part of the source code. For Example:
- #ifdef PROFILE
- CALL wclock_on (ng, iNLM, 13)
- #endif
- is used to activate time profiling during execution.