const与数组声明
来源:互联网 发布:淘宝联系卖家客服 编辑:程序博客网 时间:2024/05/17 04:14
在libidn的stringprep.h里面,有这样的声明:
声明的实现在c文件里面,例如profiles.c
libidn是可以在vs里面编译通过的,我有一个c++项目要用libidn,但在编译时会报错,
error C2133: 'stringprep_profiles' : unknown size
在MSDN里面,对error C2133的说明为:http://msdn.microsoft.com/en-us/library/c13wk277(VS.71).aspx
An unsized array is declared as a member of a class, structure, union, or enumeration. The /Za (ANSI C) option does not allow unsized member arrays.
The following sample generates C2133:
// C2133.cpp// compile with: /Zastruct X{ int a[0]; // C2133, unsized array};int main(){}
如果你将stringprep.h的数组声明改为:
extern IDN_DLL_VAR const Stringprep_profiles* stringprep_profiles;
extern IDN_DLL_VAR const Stringprep_table_element* stringprep_rfc3454_A_1;
可以编过,但运行时是错误的,stringprep_profiles指向的0x00000003。
这是为什么呢?不至于要将所有的数组都指定大小吧。
先看一个简化的例子,下面的例子是可以编过的,并且运行正常
如果在数组前面加一个const,如注释掉的语句,这时就会编译不过去。
如果你加了const并且将ArrayStruct.cpp的文件名改为ArrayStruct.c也可以编过去并正常运行。
通过上面的例子可以看出c++和c里面对const和数组声明的不同处理了。
- const与数组声明
- const int *a, int const *a,int * const a,区别,指针数组,数组指针,声明与定义
- const int *a, int const *a,int * const a,区别,指针数组,数组指针,声明与定义(转)
- const int *a, int const *a,int * const a,区别,指针数组,数组指针,声明与定义
- const int *a, int const *a,int * const a,区别,指针数组,数组指针,声明与定义
- const int *a, int const *a,int * const a,区别,指针数组,数组指针,声明与定义
- const int *a, int const *a,int * const a,区别,指针数组,数组指针,声明与定义
- const int *a, int const *a,int * const a,区别,指针数组,数组指针,声明与定义
- const int *a, int const *a,int * const a,区别,指针数组,数组指针,声明与定义
- const int *a, int const *a,int * const a,区别,指针数组,数组指针,声明与定义
- const int *a, int const *a,int * const a,区别,指针数组,数组指针,声明与定义
- 指针,数组与const
- C++ static、const对象声明与定义
- 数组的声明与初始化
- 数组如何声明与初始化?
- 数组的声明与使用
- 数组的声明与使用
- C++中 声明 数组 和 const 变量 时关键字顺序
- malloc()、calloc()、realloc()
- 开始学struts。
- 常见的动态内存错误
- 在程序退出main()函数之后,还有可能执行一部分代码吗?
- 总线错误和段错误相关概念
- const与数组声明
- 字符串拷贝和内存拷贝函数
- 字符串和内存数据比较函数
- 读《沉思录》后,与师妹的对答—— 所说并非自己所能做到,只是见解。说和做不是直接对等关系
- 连接字符串的函数
- myeclipse 修改项目名称
- 查找字符/字符串的函数
- 什么是标准预定义宏
- 断言 assert(表达式) 相关概念