我想知道是否有任何方法可以在函数调用之间保留结构的成员值,以防该结构是本地结构。对于原始数据类型,我们将它们声明为静态,并且数据将在函数调用之间保留。如果在调用部分定义结构或作为全局变量,我知道我们可以保留它。但只是好奇是否有其他替代方法可以在函数调用之间保留本地结构值。
struct A
{
int mem1;
}
void f1(void)
{
struct A var1;
/*Now this var1 is a local variable. Declaring it as static will not help to retain value of mem1 across function calls I guess. */
}
最佳答案
如 wikipedia 中所述,只是为了做好准备:
...static is a reserved word controlling both lifetime (as a static variable) and visibility (depending on linkage). The word static is also used in languages influenced by C, such as Java.
静态被定义为存储类。存储类定义了变量和/或函数的范围和生命周期。存储类位于类型之前。不管它是否原始。
关于c - 跨函数调用保留结构体的成员值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47081482/