Simple Define Statements
The SYMBOL is any valid C symbol name (by convention, #define names are all uppercase). The value can be a simple number or an expression.
Like variable declarations, a constant declaration needs a comment explains it. This comment helps create a dictionary of constants.
Constant expressions
If the value of a #define statement is a compound expression, you can run problems. The following code looks correct, but it hides a fatal flaw.
This another example of how the C preprocessor can hide problems. Clearly LENGTH is 10 + 20, which is 30. So LENGTH is 30, right? Wrong. LENGTH literally 10 + 20 , and:
To avoid problems like this, always surround all #define expressions with parenthesis ( () ). Thus, the statement:
If the value of a constant is anything other than a single number, enclose it in parentheses.
Useful Links:
http://www.oualline.com/style/c06.html
Useful Links:
http://www.oualline.com/style/c06.html
No comments:
Post a Comment