The Psychology of Quality and More |
CHAPTER 8 : Language Usage
8.13 Conditional compilationThe #if and #ifdef statements allows conditional compilation, which can be used, for example, to embed debug code or to enable different sections of a program which is to be ported to several different environments:
#if LANGUAGE == ENGLISH
This may make it easy to compile different language versions, but it makes the code difficult to read, as what is effectively one statement has become a more complex block. The complexity in this type of usage can sometimes be moved elsewhere:
/* messages.c */ "Bonjour, Monde", ... ----------------------------------------------- Note that #elif and #error are ANSI C keywords. A backwards portable approach would be to use a sequence of #ifdef..#endif.
#ifdef (or #if defined in ANSI) is typically used in a similar manner to #if, conditionally enabling portions of code.
#ifndef is typically used to flag an error or provide default values where a symbol has not been defined:
#ifndef BUFFER_SIZE
|
Site Menu |
Quality: | Quality Toolbook | Tools of the Trade | Improvement Encyclopedia | Quality Articles | Being Creative | Being Persuasive | |
And: | C Style (Book) | Stories | Articles | Bookstore | My Photos | About | Contact | |
Settings: | Computer layout | Mobile layout | Small font | Medium font | Large font | Translate | |
You can buy books here |
And the big |