> For the complete documentation index, see [llms.txt](https://docs.aic-eec.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.aic-eec.com/c-c++-for-embedded-programming/c-c++-preprocessing/conditional-compilation.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
