c++ - "Error: incomplete type "unsigned char[] ""在 Solaris 机器上用 SUN C++ 编译时

标签 c++ linux types compilation solaris

我将 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/

相关文章:

linux - 无法让 Terminus 与 PHPStorm 一起工作

linux - Linux中如何证明目录是一个文件

javascript - 构造函数的 Purescript FFI 类型定义

char* 到 float*

c++ - 如何释放指针 vector 中的元素?

c++ - 什么对我来说更好 : vector or list?

c++ - 如何通过专门化在具有单独声明和定义的模板化类的方法上使用 std::enable_if

linux - Ubuntu Linux 上的 Android Studio 崩溃

php - 根据 MYSQL 数据类型检查 PHP 变量类型

c++ - 在带有 Eclipse 的 Linux 中是否有 wxwidgets 的图形用户界面设计器?