Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> การเขียนโปรแกรม C

C Preprocessors: คำสั่งประมวลผลก่อนคอมไพล์

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