简体   繁体   English

文件开头的静态和非静态变量定义区别

[英]static and non-static variable definition at the start of the file difference

Looking at an ST example file for one of its devices.查看其设备之一的 ST 示例文件。

On the same .c file there are different definitions.在同一个 .c 文件上有不同的定义。

Curious to know what might be the reason for some of the definitions to be static and some not.很想知道某些定义是静态的而有些不是静态的原因可能是什么。

PLACE_IN_SECTION("BLE_DRIVER_CONTEXT") static tListNode HciAsynchEventQueue; // static

PLACE_IN_SECTION("BLE_DRIVER_CONTEXT") static TL_CmdPacket_t *pCmdBuffer; // static

PLACE_IN_SECTION("BLE_DRIVER_CONTEXT") HCI_TL_UserEventFlowStatus_t UserEventFlow; // not static

All appear at the top of the file .全部出现在文件的顶部。 One after another.相继。 All are used inside the file only.所有仅在文件内部使用。

static file level (global) variables do not have external linkage and will not be seen from other compilation units (more simple files). static文件级(全局)变量没有外部链接,不会被其他编译单元(更简单的文件)看到。 They have the same storage duration as non static variables but their "visibility" is limited to one compilation unit (source file).它们与非static变量具有相同的存储持续时间,但它们的“可见性”仅限于一个编译单元(源文件)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM