Preprocessor
Macro Constants
Object-like macros name compile-time constants before the compiler sees the program.
object-like macro
The preprocessor replaces a macro name with its replacement text before parsing.
runtime use
The trace uses the expanded value so the replay stays aligned with source lines.
Macro Constants
macro_constants.c
Replay: real traced execution (multi-file project)
#include <stdio.h>
#define TAX_RATE 8
int main(void) {
int price = 20;
int taxRate = 8;
int tax = price * taxRate / 100;
int total = price + tax;
printf("total=%d\n", total);
return 0;
}
#include <stdio.h>
#define TAX_RATE 8
int main(void) {
int price = 15;
int taxRate = 8;
int tax = price * taxRate / 100;
int total = price + tax;
printf("total=%d\n", total);
return 0;
}
#include <stdio.h>
#define TAX_RATE 8
int main(void) {
int price = 30;
int taxRate = 8;
int tax = price * taxRate / 100;
int total = price + tax;
printf("total=%d\n", total);
return 0;
}
price ← 20, taxRate ← 8, tax ← 1, total ← 21
5int main(void) {6 int price→ 20 = 20; //@price=15, 307 int taxRate→ 8 = 8;8 int tax→ 1 = price20 * taxRate8 / 100;9 int total→ 21 = price20 + tax1;1011 printf("total=%d\n", total21);12 return 0;13}outputtotal=21
price ← 15, taxRate ← 8, tax ← 1, total ← 16
5int main(void) {6 int price→ 15 = 15;7 int taxRate→ 8 = 8;8 int tax→ 1 = price15 * taxRate8 / 100;9 int total→ 16 = price15 + tax1;1011 printf("total=%d\n", total16);12 return 0;13}outputtotal=16
price ← 30, taxRate ← 8, tax ← 2, total ← 32
5int main(void) {6 int price→ 30 = 30;7 int taxRate→ 8 = 8;8 int tax→ 2 = price30 * taxRate8 / 100;9 int total→ 32 = price30 + tax2;1011 printf("total=%d\n", total32);12 return 0;13}outputtotal=32