错误:初始化元素不是常量
int * const front = mmap(0, sizeof(int), PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
int * const back = mmap(0, sizeof(int), PROT_READ|PROT_WRITE|PROT_EXEC, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
int * const buffer = mmap(0, sizeof(int)*50, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
我收到以下错误:“错误:初始化器元素不是常量”
如何删除它? 我知道如果我执行类似 int a[b];
的操作,它不会起作用,但为什么会发生在这里呢?
int * const front = mmap(0, sizeof(int), PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
int * const back = mmap(0, sizeof(int), PROT_READ|PROT_WRITE|PROT_EXEC, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
int * const buffer = mmap(0, sizeof(int)*50, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
I am getting the following error: "error: initializer element is not constant"
How do I remove it?
I know it won't work if I do something like int a[b];
, but why is it happening here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您还没有说过,但您很可能正在使用 C 而不是 C++ 工作,并且这些是具有静态持续时间的变量?在 C 中,您只能使用编译时常量表达式来初始化静态变量。函数调用不是编译时常量表达式。
You haven't said, but it's pretty likely that you're working in C, not C++, and that these are variables with static duration? In C, you can only intialize a static variable with something that is a compile-time constant expression. A function-call is not a compile-time constant expression.