CH 14 deitel how to program
CH 14 deitel how to program
1. Introduction
2. #include Directive
3. #define Directive
Symbolic Constants: Replaces all instances of a constant with its value, e.g., #define
PI 3.14159.
Macros:
o Can include arguments for operations.
o Example:
c
Copy code
#define CIRCLE_AREA(x) ((PI) * (x) * (x))
Common Pitfall: Avoid side effects like modifying variables in macro arguments, as
they can lead to errors due to multiple evaluations.
4. Conditional Compilation
Directives:
o #if, #elif, #else, #endif are used to include/exclude code sections based on
conditions.
o #ifdefand #ifndef are shorthand for checking whether a name is defined.
Useful for including debugging code selectively.
6. # and ## Operators
c
Copy code
#define HELLO(x) puts("Hello, " #x)
c
Copy code
#define TOKENCONCAT(x, y) x##y
7. Line Numbers
#line directive can renumber subsequent lines and set a new filename for error reporting.
Syntax:
c
Copy code
#line 100 "file1.c"
9. Assertions
Use the assert macro (from <assert.h>) to test conditions during development.
Example:
c
Copy code
assert(x <= 10);