# Conditional Compilation

โดยปกติเทคนิคแบบนี้เราจะเจอภายใน header file หรือ library เป็นหลักครับ โดยมักจะใช้เพื่อเลือกเงื่อนไขก่อนการทำการคอมไพล์ ดังนั้นเงื่อนไขในการใช้เทคนิคการ Preprocessing ที่เป็นเงื่อนไขนั้นจะใช้เลือก สถาปัตยกรรม ฟังก์ชันหรือตัว source code ที่จะนำไป compile โดยตัวเงื่อนไขลักษณะนี้จะประกอบไปด้วย

* **#Ifdef <-- ถ้า เปิดเงื่อนไขถ้าเป็น 1 จะทำงานในเงื่อนไขนี้**
* **#ifndef <-- ถ้า-ไม่ ถ้าเงื่อนไขไม่เป็น 1 เป็น 0 จะทำงานในเงื่อนไขนี้**&#x20;
* **#elif <-- เงื่อนไขอื่นอันนี้ก็ทำงานในกรณีเป็น 1**
* **#else <-- ถ้าไม่มีเงื่อนไขอื่นๆแล้วจะทำในส่วนนี้**
* **#endif <-- ใช้ปิดเงื่อนไข**

#### Example

![เงื่อนไขในการเลือก Platform ในการคอมไพล์](/files/-MQyeij0f3kDNR4aU0ai)

```c
#ifdef (KL25_PLATFORM) && !(MSP_PLOATFORM)
    kl25_initial();
#elif (MSP_PLOATFORM) && !(KL25_PLATFORM)
    msp_initial();
#else
    #error "Please specific one platform target"
#endif
```

จากโค้ดด้านบนและรูปจะเห็นการทำงานจะเป็นการเลือก platform บนบอร์ดที่จะใช้งานเพื่อให้สามารถเลือกการโปรแกรมคอมไพล์บนโค้ดชุดเดียวกันแต่แตกต่างกันเพียง library ได้โดยไม่ต้องสร้างโค้ดอีกชุด


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.aic-eec.com/c-c++-for-embedded-programming/c-programming-techniques/c-c++-preprocessing/conditional-compilation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
