1cfd3bbb56
Topic_CSS/Topic_HTML/Topic_JavaScript/Topic_Prompt/Topic_Comfyui 등 기존 카테고리 폴더를 정리하고, Topic_Graphic/Dev 등 신규 산출물과 Topics 내부 세션/메모리 기록을 동기화.
4.2 KiB
4.2 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-storage-classes | C Storage Classes | Programming_Language | draft | conceptual |
|
B | 0.86 | 2026-07-04 | 2026-07-04 |
|
|
C Storage Classes
🎯 한 줄 통찰 (One-line insight)
A static local variable inside a function survives BETWEEN separate calls to that function — the source's count() example prints 1, 2, 3 across three separate calls specifically because static makes the variable retain its value instead of resetting to 0 each time, whereas an ordinary local variable would print 1, 1, 1 — demonstrating that static fundamentally changes a variable's LIFETIME, not just its scope. [S1]
🧠 핵심 개념 (Core concepts)
- Scope vs. storage class — scope defines WHERE a variable can be used; storage class defines HOW LONG it lasts and WHERE it's stored — two independent concepts. [S1]
auto— the default storage class for local variables inside functions; rarely written explicitly since it's already the default. [S1]static— a local variable keeps its value across separate function calls (rather than resetting each call); a global variable/function markedstaticbecomes invisible outside its own file. [S1]register— suggests storing a variable in a CPU register for faster access; its address cannot be taken with&; considered mostly obsolete since modern compilers auto-optimize register allocation. [S1]extern— tells the compiler a variable/function is DEFINED in another file, used for sharing variables across multiple source files. [S1]
📖 세부 내용 (Details)
staticpreserving value across calls:void count() { static int myNum = 0; myNum++; printf("num = %d\n", myNum); } int main() { count(); count(); count(); return 0; }— outputsnum = 1,num = 2,num = 3(removingstaticwould reset to 1 each time). [S1]externsharing a variable across files:main.cdeclaresextern int shared;whiledata.cdefinesint shared = 50;, compiled together viagcc main.c data.c -o program. [S1]
⚖️ 모순 및 업데이트 (Contradictions & updates)
- static은 값을 유지, register는 사실상 구식: static이 함수 호출 간 값을 보존한다는 점과, register 키워드는 현대 컴파일러가 알아서 최적화하므로 명시적으로 쓸 필요가 거의 없다는 점이 함께 언급됨. [S1]
🛠️ 적용 사례 (Applied in summary)
현재 발견된 실제 적용 사례가 없습니다 — count() 함수가 호출될 때마다 값을 누적하는 static 카운터 패턴이 함수 호출 횟수를 추적하는 실전 활용의 대표 사례다. [S1]
💻 코드 패턴 (Code patterns)
A static local variable retaining its value across separate function calls (C):
void count() {
static int myNum = 0; // Keeps its value between calls
myNum++;
printf("num = %d\n", myNum);
}
int main() {
count(); // num = 1
count(); // num = 2
count(); // num = 3
return 0;
}
✅ 검증 상태 및 신뢰도
- 상태: draft
- 검증 단계: conceptual
- 출처 신뢰도: B (W3Schools — widely used educational reference, not a primary standards body)
- 신뢰 점수: 0.86
- 중복 검사 결과: 신규 생성 (New discovery)
🔗 지식 그래프 (Knowledge Graph)
- 상위/루트: C Tutorial
- 관련 개념: C Constants, C Scope, C Fixed Width Ints
- 참조 맥락: 저장 클래스와 변수 생명주기 — 고정폭 정수(Fixed Width Ints) 챕터로 이어짐.
📚 출처 (Sources)
- [S1] W3Schools — C Storage Classes — https://www.w3schools.com/c/c_storage_classes.php
📝 변경 이력 (Change history)
- 2026-07-04: Initial draft synthesized from the W3Schools "C Storage Classes" page (Astra wiki-curation, P-Reinforce v3.1 format).