# C/C++ Preprocessing

#### Reference : <https://www.geeksforgeeks.org/cc-preprocessors/> <https://www.coursera.org/lecture/introduction-embedded-systems/3-preprocessor-directives-VDPBC>

จากที่กล่าวไปข้างต้นจะเล่าถึงกระบวนการทำงานก่อนการ Compile โปรแกรมจนไปถึงการ Execute โปรแกรม โดยการทำงานการสร้างไฟล์รันทดสอบในโปรแกรมขึ้นมาจะมีกระบวนการดังรูปด้านล่าง

![กระบวนการสร้างไฟล์ Execute จากโปรแกรมที่เขียน](/files/-MQx92L3030uueLsp6rd)

จากขั้นดอนดังรูปจะเตรียมความพร้อมก่อนทำการ Compile จากไฟล์ source coed(.c, .cpp) และไฟล์ header(.h) เพื่อทำการสร้าง Pre-process file ในการแทนค่าหรือเตรียมกระบวนการที่จะใช้งานก่อนทำการ Compile ไว้ หลังจากนั้นเราจะได้ Assembly file ออกมาหลังกระบวนการ Compile ภาษา C เราจึงนำไฟล์ Assembly ไปทำการ Assembler หรือการคอมไฟล์ภาษา Assembly จะได้ Object file ซึ่งจะเก็บกระบวนการของโปรแกรมไว้ออกมาในการใช้งาน แล้วจึงทำการลิ้ง Environment ต่าง ๆ ที่ต้องใช้งานจึงได้จนได้ Executable ไฟล์ที่ใช้รันออกมา

โดยในหัวข้อนี้เราจะลงลึกกระบวนการในการทำ Preprocessing ของภาษา C/C++&#x20;

จริงๆแล้วกระบวนการนี้ไม่ได้เป็นกระบวนการใหม่ หรือเป็นเรื่องใหม่ที่ผู้เรียนทุกคนที่เคยเล่นภาษาโปรแกรมอย่างน้อยหนึ่งครั้งต้องเคยใช้งาน โดยที่ท่านอาจสังเกตแล้วเกิดความสงสัยหรืออาจไม่ได้สังเกตแค่เพียงเรียกใช้ในการทำงานทั่วๆไป แต่วันนี้เราจะมาลงลึกเทคนิคให้ใช้ไปประยุกต์ใช้งานกันได้กับงานของเรา โดยจะแบ่งหัวข้อที่ต้องเรียนเป็น 4 หัวข้อดังนี้

1. Macros
2. File Inclusion
3. Conditional Compilation
4. Pragma directives


---

# 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-c++-preprocessing.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.
