计算机
c base
c++ 基础 作用域及生命周期
c++ template
c++ 内存视角
c++ 函数指针
c++ 基础 基础语法
c++ 多线程
c++ 性能
c++ 类 基础
c++ 类 对象模型 类析构
c++ 类 设计模式
cmake
CMAKE环境搭建 windows
创建第一个cmakelists.txt
构建稍复杂的项目
动态链接库
EX1
EX1 START
EX1 ANSWER
EX2
EX2 START
EX2 ANSWER
EX3
EX3 START
EX3 ANSWER
变量
控制流程
函数和宏
查找和使用外部库
生成器表达式
qt 开发环境
qt c++
理解QObject 1
理解QObject 4
qt index
qt qml quick
qt ui
qt 多线程
数据结构 数组
PC问题监控及排查
PC程序性能优化
OS
TOOL
C++ STL
编程漫谈
C++实战-生产者 消费者流水线
C++实战 IO
本站点使用 MrDoc 构建
-
+
c base
a ? b : c condition a? , if true , execute b; if false , execute c; 内存、上下文 语法 # c语言历史   早期c语言某些特性是为编译器设置的 \* 预处理器:字符串替换、头文件包含、宏 \* K&R C <THE C PROGRAMMING LANGUAGE·> \* ANSI C 标准问题:语义不清晰,产生误解(语法、语义分析) 编程语言缺陷分析: 该做的没做好、不该做的做了、该做的没做 # Storage duration Every object has a property called storage duration, which limits the object lifetime. There are four kinds of storage duration in C: automatic storage duration. The storage is allocated when the block in which the object was declared is entered and deallocated when it is exited by any means (goto, return, reaching the end). One exception is the VLAs; their storage is allocated when the declaration is executed, not on block entry, and deallocated when the declaration goes out of scope, not when the block is exited(since C99). If the block is entered recursively, a new allocation is performed for every recursion level. All function parameters and non-static block-scope objects have this storage duration, as well as compound literals used at block scope(until C23) 当block结束,变量被释放;VLA(变长数组)是例外,在声明时分配内存,声明的作用域结束时候释放内存 static storage duration. The storage duration is the entire execution of the program, and the value stored in the object is initialized only once, prior to main function. All objects declared static and all objects with either internal or external linkage that aren't declared \\\_Thread\_local(until C23)thread\_local(since C23)(since C11) have this storage duration. static storage存在程序执行的整个周期,只初始化一次,static声明和具有内外部链接的变量have this storage duration thread storage duration. The storage duration is the entire execution of the thread in which it was created, and the value stored in the object is initialized when the thread is started. Each thread has its own, distinct, object. If the thread that executes the expression that accesses this object is not the thread that executed its initialization, the behavior is implementation-defined. All objects declared \\\_Thread\_local(until C23)thread\_local(since C23) have this storage duration. (since C11) allocated storage duration. The storage is allocated and deallocated on request, using dynamic memory allocation functions. # Linkage Linkage refers to the ability of an identifier (variable or function) to be referred to in other scopes. If a variable or function with the same identifier is declared in several scopes, but cannot be referred to from all of them, then several instances of the variable are generated. The following linkages are recognized: no linkage. The variable or function can be referred to only from the scope it is in (block scope). All block scope variables that are not declared extern have this linkage, as well as all function parameters and all identifiers that aren't functions or variables. internal linkage. The variable or function can be referred to from all scopes in the current translation unit. All file scope variables which are declared static or constexpr(since C23) have this linkage, and all file scope functions declared static (static function declarations are only allowed at file scope). external linkage. The variable or function can be referred to from any other translation units in the entire program. All file scope variables which are not declared static or constexpr(since C23) have this linkage, all file scope function declarations which are not declared static, all block scope function declarations, and, additionally, all variables or functions declared extern have this linkage unless a prior declaration with internal linkage is visible at that point. If the same identifier appears with both internal and external linkage in the same translation unit, the behavior is undefined. This is possible when tentative definitions are used. # scope Each identifier that appears in a C program is visible (that is, may be used) only in some possibly discontiguous portion of the source code called its scope. Within a scope, an identifier may designate more than one entity only if the entities are in different name spaces. C has four kinds of scopes:
peipeo
2026年5月5日 08:59
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
Markdown文件
PDF文档(打印)
分享
链接
类型
密码
更新密码