Ç - 初始元素不是常数 [英] C - initializer element is not constant

查看:90
本文介绍了Ç - 初始元素不是常数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的code的在C片段:

Here's a snippet of my code in C:

const char *d = "dictionary.dict";

struct dictionary *dict =
        dictionary_load_lang(d); // Compile error here

该型dictionary_load_lang()是结构字典* dictionary_load_lang(为const char *郎)

当试图编译编译器说:初始元素不是常量,我不明白为什么。这是怎么回事?

When trying to compile the compiler says "initializer element is not constant" and I can't see why. What's going on?

推荐答案

dictionary_load_lang()是一个函数,因此非恒定。你不能使用非常量静态存储变量(阅读:全球和/或静态

dictionary_load_lang() is a function, hence a non-constant. You can't use a non-constants for static storage variables (read: global and/or static):

按C99标准:第6.7.8:

As per C99 Standard: Section 6.7.8:

在初始化所有前任pressions为具有静态对象
  存储时间应保持恒定前pressions或字符串。

All the expressions in an initializer for an object that has static storage duration shall be constant expressions or string literals.

不过,您可以如果一个函数内的非静态变量做这样的初始化。

However, you can do such an initialization if within a function and for a non-static variable.

这篇关于Ç - 初始元素不是常数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆