155/317
6 - STMicroelectronics Programming Tools
As an example, let us consider a product for which two different suppliers of displays are con-
sidered. These two displays are almost the same, except for a few differences. The product is
produced for some time with one type of display, then a better price has been negotiated with
the second supplier, so the production switches to the second type of display. Later, for similar
reason but the other way, products with the first type of display are manufactured.
If this situation is considered at design time, the best thing is to write the program with the ap-
propriate code for both cases. Then, by changing one line at the top of the source file, either
the code for the first display or the code for the second display is assembled. The program
couldbestructuredlikethis:
#DEFINE FIRST_TYPE
some program source lines...
#IFDEF FIRST_TYPE ; first conditional block
source text for the first type of display...
#ELSE
source text for the second type of display...
#ENDIF
continuation of the program...
#IFDEF FIRST_TYPE ; second conditional block
source text for the first type of display...
#ELSE
source text for the second type of display...
#ENDIF
continuation of the program...
#IFDEF FIRST_TYPE ; third conditional block
source text for the first type of display...
#ELSE
source text for the second type of display...
#ENDIF
continuation of the program...
end ; end of the program
In this example, the program is changed in three places to accommodate the change of the
display. The pseudo-op
IFDEF is true if the identifier that follows it is defined in the source; it is
false otherwise. The pseudo-op
#DEFINE creates an identifier that equals an empty string; but
the identifier does exist, which is what we are testing.
In this version, the program will produce the version for the first display. To assemble the pro-
gram for the second display, the line: