4.2.4. Else. Red Hat ENTERPRISE LINUX 4 - USING BINUTILS, ENTERPRISE LINUX 4 - DEVELOPER TOOLS GUIDE
Reklama
Reklama
40 Chapter 4. Conditionals can generally be simplified to just #if BUFSIZE = 1024 , since if BUFSIZE is not defined, it will be interpreted as having the value zero.
If the defined operator appears as a result of a macro expansion, the C standard says the behavior is undefined. GNU cpp treats it as a genuine defined operator and evaluates it normally. It will warn wherever your code uses this feature if you use the command-line option -pedantic , since other compilers may handle it differently.
4.2.4. Else
The #else directive can be added to a conditional to provide alternative text to be used if the condition fails. This is what it looks like:
#if expression text-if-true
#else /* Not expression */ text-if-false
#endif /* Not expression */
If expression is nonzero, the text-if-true is included and the text-if-false is skipped. If expression is zero, the opposite happens.
You can use #else with #ifdef and #ifndef , too.
4.2.5. Elif
One common case of nested conditionals is used to check for more than two possible alternatives. For example, you might have
#if X == 1
...
#else /* X != 1 */
#if X == 2
...
#else /* X != 2 */
...
#endif /* X != 2 */
#endif /* X != 1 */
Another conditional directive, #elif , allows this to be abbreviated as follows:
#if X == 1
...
#elif X == 2
...
#else /* X != 2 and X != 1*/
...
#endif /* X != 2 and X != 1*/
Stáhnout
Reklama