Files
2nd/10_Wiki/Topic_Programming/Topic_C/C_Organize_Code.md
T
Antigravity Agent e9cbf23ab5 docs(10_Wiki): Dev 폴더 누락분 반영 — Topic_Programming으로 통합
이전 재구성 작업에서 Dev/ 폴더가 누락되었던 것을 반영.

- Dev/Topic_Programming(중첩 폴더, 78개)은 Dev 자체 최상위 폴더들
  (Architecture/Conventions/Engineering_Intelligence 등)과 완전 중복이라 제거.
- Dev 최상위 엔지니어링 지식 폴더(Architecture/Conventions/Engineering_Intelligence/
  Failure_Library/Generalized_Principles/Language/Pattern_Catalog/Platform_Guides/
  Subsystems, 77개)는 이미 Topic_Programming/Topic_Programming에 더 최신 버전이
  존재해 중복 제거(고유 콘텐츠 1개는 예외 처리하여 이동 보존).
- Dev의 W3Schools 언어 튜토리얼 폴더(Topic_C/CPP/CSS/CSharp/HOWTO/HTML/Java/
  JavaScript/PHP/Python/SQL/W3CSS, 1201개)는 전부 Topic_Programming 하위로 이동.
- 에이전트 운영 상태(.astra/docs)는 그대로 유지, 콘텐츠 폴더만 정리.
- Topic_Programming 최종 문서 수: 2784 → 3985.
2026-07-05 00:39:13 +09:00

4.3 KiB

id, title, category, status, verification_status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, created_at, updated_at, review_reason, merge_history, tags, raw_sources, applied_in, github_commit
id title category status verification_status canonical_id aliases duplicate_of source_trust_level confidence_score created_at updated_at review_reason merge_history tags raw_sources applied_in github_commit
c-organize-code C Organize Code Programming_Language draft conceptual
header files
include guard
modular programming
C 코드 조직화
B 0.85 2026-07-04 2026-07-04
c
programming-language
w3schools
header-files
modular-programming
https://www.w3schools.com/c/c_organize_code.php

C Organize Code

🎯 한 줄 통찰 (One-line insight)

The #ifndef/#define/#endif include guard exists to solve a problem that's invisible in small single-file programs but inevitable in multi-file ones — preventing the SAME header from being included twice (directly or transitively through other headers) which would otherwise cause duplicate-declaration compile errors, making the include guard a defensive pattern every C header should carry regardless of whether the problem has actually occurred yet. [S1]

🧠 핵심 개념 (Core concepts)

  • Modular programming — splitting code into smaller, reusable .c/.h file pairs for readability, maintainability, and debuggability; optional for small programs, valuable for larger ones. [S1]
  • Header files (.h) — declare functions, share variables/constants/macros across files, and organize code into logical modules; typically contain declarations, macros, and struct definitions (not full function bodies). [S1]
  • Include guard (#ifndef/#define/#endif) — prevents a header from being included more than once by accident, avoiding duplicate-declaration errors; a standard, recommended practice in every C header. [S1]
  • Separation of declaration and definition — the .h file declares function signatures; the corresponding .c file provides the actual function bodies. [S1]
  • Multi-file compilation — the compiler must be given ALL relevant .c files at once (e.g. gcc main.c calc.c -o program) to link them into one executable. [S1]

📖 세부 내용 (Details)

  • Header file with include guard: #ifndef CALC_H #define CALC_H int add(int x, int y); int subtract(int x, int y); #endif (calc.h). [S1]
  • Corresponding source file: #include "calc.h" int add(int x, int y) { return x + y; } int subtract(int x, int y) { return x - y; } (calc.c). [S1]
  • Consuming the module: #include <stdio.h> #include "calc.h" int main() { printf("5 + 5 = %d\n", add(5, 5)); printf("6 - 4 = %d\n", subtract(6, 4)); return 0; } (main.c). [S1]
  • Compiling multiple files together: gcc main.c calc.c -o program. [S1]

⚖️ 모순 및 업데이트 (Contradictions & updates)

  • include guard의 필요성: 작은 프로그램에서는 문제가 드러나지 않지만, 헤더가 여러 파일에서 직간접적으로 중복 포함될 경우 중복 선언 에러가 발생할 수 있어 모든 C 헤더에 include guard를 넣는 것이 표준 관행으로 권장됨. [S1]

🛠️ 적용 사례 (Applied in summary)

현재 발견된 실제 적용 사례가 없습니다 — calc.h/calc.c/main.c로 나눈 계산기 모듈 예제가 여러 파일로 나뉜 프로그램을 gcc로 함께 컴파일하는 실전 워크플로우를 그대로 보여준다. [S1]

💻 코드 패턴 (Code patterns)

A header file with an include guard, plus the gcc command to compile the multi-file project (C):

// calc.h
#ifndef CALC_H
#define CALC_H
int add(int x, int y);
int subtract(int x, int y);
#endif
gcc main.c calc.c -o program

검증 상태 및 신뢰도

  • 상태: draft
  • 검증 단계: conceptual
  • 출처 신뢰도: B (W3Schools — widely used educational reference, not a primary standards body)
  • 신뢰 점수: 0.85
  • 중복 검사 결과: 신규 생성 (New discovery)

🔗 지식 그래프 (Knowledge Graph)

📚 출처 (Sources)

📝 변경 이력 (Change history)

  • 2026-07-04: Initial draft synthesized from the W3Schools "C Organize Code" page (Astra wiki-curation, P-Reinforce v3.1 format).