本文介绍了灵活的数组成员在C ++中是否有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C99中,您可以声明结构的一个弹性数组成员,如下所示:

  struct blah 
{
int foo [];
};但是,当有人在工作时试图使用C ++中的clang来编译一些代码时,那个语法并没有使用。工作。 (它一直在与MSVC工作。)我们不得不将其转换为:

  struct blah 
{
int foo [0];
};

通过C ++标准,我没有发现灵活的成员数组;我一直认为 [0] 是一个无效的声明,但显然对于一个灵活的成员数组是有效的。灵活的成员数组在C ++中是否真的有效?如果是,是正确的声明 [] [0]


In C99, you can declare a flexible array member of a struct as such:

struct blah
{
    int foo[];
};

However, when someone here at work tried to compile some code using clang in C++, that syntax did not work. (It had been working with MSVC.) We had to convert it to:

struct blah
{
    int foo[0];
};

Looking through the C++ standard, I found no reference to flexible member arrays at all; I always thought [0] was an invalid declaration, but apparently for a flexible member array it is valid. Are flexible member arrays actually valid in C++? If so, is the correct declaration [] or [0]?

解决方案

C++ was first standardized in 1998, so it predates the addition of flexible array members to C (which was new in C99). There was a corrigendum to C++ in 2003, but that didn't add any relevant new features. The next revision of C++ (C++0x) is still under development, and it seems flexible array members aren't added to it.

这篇关于灵活的数组成员在C ++中是否有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 03:25