我将 unsigned char tmp[];
定义为结构的成员。
在 Linux RedHat 上用 g++4 编译时它不会报错。 但是在 Solaris 5.10 机器上使用 Sun C++ 编译时出现错误:
Error: In this declaration "
tmp
" is of an incomplete type "unsigned char[]
".
Sun C++ 是否有任何编译选项可以编译?
我读过关于不完整类型的内容,我应该将其更改为指针吗?那会有问题,因为我有很多相同类型的定义。 为什么编译结果不同?
最佳答案
给定代码
struct
{
...,
char tmp[];
};
tmp
是一个 flexible array member .
这是一个 C 语言结构,它是 not valid in C++ until C++14 , 但作为扩展被 GCC 支持。
latest version of Solaris Studio does support C++14 via the -std=c++14
option.
注意零长度数组,比如
struct
{
...,
char tmp[ 0 ];
};
不与灵活数组成员相同,您的 Studio 编译器版本可能不支持 -features=zla
选项。这是not supported by Solaris Studio 12.2, for example.
关于c++ - "Error: incomplete type "unsigned char[] ""在 Solaris 机器上用 SUN C++ 编译时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47058431/