【发布时间】:2014-06-16 20:02:25
【问题描述】:
我想拥有 const 的全局变量,但它们应该在 mexFunction() 函数中定义。这是因为它们应该设置为一些来自 Matlab 的输入值。 (mexFunction() 基本上是我的 main() 函数。)
这样的事情可能吗?
main.h
extern int const myConstGlobal;
main.c
mexFunction(input)
{
int const myConstGlobal = input;
}
函数.c
#include main.h
foo(myConstGlobal){}
我目前理解的一些链接:
shared-global-variables-in-C 中解释了如何使用共享全局变量。
the second answer of this link 中解释了如何使用共享的全局 const 变量
...你必须声明:
extern int const const_int ;
在标题中,并且:
extern int const const_int = fn() ;
在一个(并且只有一个)源文件中。
但是像这样我需要函数来传递我想要规避的输入值。
【问题讨论】:
-
你必须把它的定义放在一个函数之外。否则它不是全局的。
标签: c constants declaration definition mex