Preprocessor directives เริ่มต้นด้วย # ประมวลผลก่อนการคอมไพล์จริง
รายการสำคัญ
| Directive | คำอธิบาย |
|---|---|
#include | รวม header file |
#define | กำหนด macro/constant |
#undef | ยกเลิก macro |
#if, #ifdef, #ifndef | เงื่อนไขคอมไพล์ |
#else, #elif, #endif | ส่วนเลือกของเงื่อนไข |
#error | แสดง error message |
#pragma | คำสั่งเฉพาะคอมไพเลอร์ |
#line | เปลี่ยน line number |
ตัวอย่าง
#define PI 3.14159
#define SQUARE(x) ((x)*(x))
#ifdef DEBUG
printf("Debug mode\n");
#endif
#if VERSION > 2
// code for version 3+
#endif