angie
angie

Reputation: 53

"Error: incomplete type "unsigned char[]" " when compiling with SUN C++ on Solaris machine

I have a definition of unsigned char tmp[]; as a member of a structure.

When compiling with g++4 on Linux RedHat it does not complain. But when compiling with Sun C++ on Solaris 5.10 machine I get an error:

Error: In this declaration "tmp" is of an incomplete type "unsigned char[]".

Are there any compile options for Sun C++ to make it compile?

I've read about the incomplete types, should I change it to a pointer? That would be problematic because I have many occurrences of the same kind of definitions. Why is the difference in compilation results?

Upvotes: 3

Views: 601

Answers (1)

Andrew Henle
Andrew Henle

Reputation: 1

Given the code

struct
{
    ...,
    char tmp[];
};

tmp is a flexible array member.

That is a C language construct that was not valid in C++ until C++14, but was supported as an extension by GCC.

The latest version of Solaris Studio does support C++14 via the -std=c++14 option.

Note that a zero-length array, such as

struct
{
    ...,
    char tmp[ 0 ];
};

is not the same as a flexible array member, and the -features=zla option may not be supported by your version of the Studio compiler. It's not supported by Solaris Studio 12.2, for example.

Upvotes: 4

Related Questions