docs(10_Wiki): Topic_Business/General/Graphic/Programming을 Topics/ 하위로 이동
최상위 10_Wiki/Topic_*였던 4개 카테고리 폴더를 10_Wiki/Topics/Topic_* 로 재배치. 콘텐츠 변경 없음(순수 폴더 이동) — Topics/ 하위 나머지 폴더는 이미 지난 커밋에서 전부 정리된 상태(잔존 항목은 에이전트 운영 상태 및 사용자가 보존을 요청한 업데이트0615/무제 3.canvas 뿐).
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
---
|
||||
id: c-macros
|
||||
title: "C Preprocessor and Macros"
|
||||
category: "Programming_Language"
|
||||
status: "draft"
|
||||
verification_status: "conceptual"
|
||||
canonical_id: ""
|
||||
aliases: ["#define", "#ifdef", "conditional compilation", "C 전처리기와 매크로"]
|
||||
duplicate_of: ""
|
||||
source_trust_level: "B"
|
||||
confidence_score: 0.86
|
||||
created_at: 2026-07-04
|
||||
updated_at: 2026-07-04
|
||||
review_reason: ""
|
||||
merge_history: []
|
||||
tags: ["c", "programming-language", "w3schools", "preprocessor", "macros"]
|
||||
raw_sources: ["https://www.w3schools.com/c/c_macros.php"]
|
||||
applied_in: []
|
||||
github_commit: ""
|
||||
---
|
||||
|
||||
# [[C Preprocessor and Macros]]
|
||||
|
||||
## 🎯 한 줄 통찰 (One-line insight)
|
||||
`#define PI 3.14` doesn't create a variable at all — the preprocessor performs a pure TEXT REPLACEMENT of every literal occurrence of `PI` with `3.14` BEFORE the compiler ever sees the code, meaning macros exist in an entirely different phase from variables/constants (which are compiled), which is also why parameterized macros like `SQUARE(x)` need careful parenthesization — they're substituting raw text, not evaluating an expression with real function-call semantics. [S1]
|
||||
|
||||
## 🧠 핵심 개념 (Core concepts)
|
||||
- **Preprocessor** — runs BEFORE actual compilation; handles directives (lines starting with `#`) like including files and defining macros. [S1]
|
||||
- **`#include`** — angle brackets `< >` for standard libraries, double quotes `" "` for your own header files. [S1]
|
||||
- **`#define NAME value`** — creates a macro; every literal occurrence of `NAME` in the code is textually replaced with `value` before compilation. [S1]
|
||||
- **Parameterized macros** — `#define SQUARE(x) ((x) * (x))` behaves like a function shortcut, but is really TEXT SUBSTITUTION, so careful parenthesization is required to avoid operator-precedence mistakes. [S1]
|
||||
- **`#ifdef` / `#ifndef`** — conditional compilation; includes or skips code blocks depending on whether a macro is defined, useful for debug builds or program variants. [S1]
|
||||
|
||||
## 📖 세부 내용 (Details)
|
||||
- Basic value macro: `#define PI 3.14 int main() { printf("Value of PI: %.2f\n", PI); return 0; }`. [S1]
|
||||
- Parameterized macro: `#define SQUARE(x) ((x) * (x)) printf("Square of 4: %d\n", SQUARE(4));`. [S1]
|
||||
- Conditional compilation gated on a defined macro: `#define DEBUG int main() { #ifdef DEBUG printf("Debug mode is ON\n"); #endif return 0; }` — if `DEBUG` were undefined, that block would be skipped entirely. [S1]
|
||||
|
||||
## ⚖️ 모순 및 업데이트 (Contradictions & updates)
|
||||
- **매크로는 변수가 아니라 텍스트 치환**: #define PI 3.14는 컴파일 전에 코드상의 PI를 문자 그대로 3.14로 바꿔치기하는 전처리 단계 작업이며, 변수나 상수처럼 컴파일되는 개념이 아니라는 점이 확인됨. [S1]
|
||||
|
||||
## 🛠️ 적용 사례 (Applied in summary)
|
||||
DEBUG 매크로가 정의되어 있을 때만 디버그 메시지를 출력하는 조건부 컴파일이 원문에서 직접 실전 활용 사례로 제시됨(디버깅이나 프로그램 버전 분기에 유용). [S1]
|
||||
|
||||
## 💻 코드 패턴 (Code patterns)
|
||||
Conditional compilation — code included only if a macro is defined (C):
|
||||
```c
|
||||
#define DEBUG
|
||||
int main() {
|
||||
#ifdef DEBUG
|
||||
printf("Debug mode is ON\n");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
## ✅ 검증 상태 및 신뢰도
|
||||
- **상태:** draft
|
||||
- **검증 단계:** conceptual
|
||||
- **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body)
|
||||
- **신뢰 점수:** 0.86
|
||||
- **중복 검사 결과:** 신규 생성 (New discovery)
|
||||
|
||||
## 🔗 지식 그래프 (Knowledge Graph)
|
||||
- **상위/루트:** [[C Tutorial]]
|
||||
- **관련 개념:** [[C Type Conversion]], [[C Organize Code]], [[C Null]]
|
||||
- **참조 맥락:** 전처리기와 매크로 — NULL(Null) 챕터로 이어짐.
|
||||
|
||||
## 📚 출처 (Sources)
|
||||
- [S1] W3Schools — C Preprocessor and Macros — https://www.w3schools.com/c/c_macros.php
|
||||
|
||||
## 📝 변경 이력 (Change history)
|
||||
- 2026-07-04: Initial draft synthesized from the W3Schools "C Preprocessor and Macros" page (Astra wiki-curation, P-Reinforce v3.1 format).
|
||||
Reference in New Issue
Block a user