gpt4 book ai didi

c - 本地调用静态变量是否正确?

转载 作者:太空狗 更新时间:2023-10-29 15:49:00 27 4
gpt4 key购买 nike

众所周知,C语言在C程序中支持两种通过变量分配内存的方式:

1) Static allocation is what happens when you declare a static variable. Each static variable defines one block of space, of a fixed size. The space is allocated once, when your program is started, and is never freed.

2) Automatic allocation happens when you declare an automatic variable, such as a function argument or a local variable. The space for an automatic variable is allocated when the compound statement containing the declaration is entered, and is freed when that compound statement is exited.

(这是来自 http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_3.html 的完整引述)

问题是:就内存分配而言,在“本地”函数中调用静态变量是否正确?为什么?提前感谢大家。

附言欢迎引用 C 标准。

最佳答案

C 标准没有定义局部变量 的术语。 自动静态是指存储时长

C11 (n1570), § 6.2.4 Storage durations of objects

An object has a storage duration that determines its lifetime.

关于c - 本地调用静态变量是否正确?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15134916/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com