问题描述
我有SDCC的问题。我的code(这我从另一个编译器试图端口)使用灵活的阵列成员结构。然而,当我尝试编译以下code:
I have an issue with SDCC. My code (which I am attempting to port from another compiler) uses structs with flexible array members. However, when I try to compile the following code:
/** header of string list */
typedef struct {
int nCount;
int nMemUsed;
int nMemAvail;
} STRLIST_HEADER;
/** string list entry data type */
typedef struct {
int nLen;
char str[];
} STRLIST_ENTRY;
/** string list data type */
typedef struct {
STRLIST_HEADER header;
STRLIST_ENTRY entry[];
} STRLIST; // By the way, this is the line the error refers to.
int main()
{
return 0;
}
SDCC提供了以下错误:
SDCC gives the following error:
$ sdcc -mz80 -S --std-c99 test.c
test.c:18: warning 186: invalid use of structure with flexible array member
test.c:18: error 200: field 'entry' has incomplete type
怎么办?这code编译gcc的就好了,何况我使用的其他Z80的编译器。
What gives? This code compiles just fine in gcc, not to mention the other z80 compiler I'm using.
编辑:我发现这SDCC错误这似乎是相关的。莫非,如果它是怎么有人解释?
I found this SDCC bug which seems to be related. Could someone explain if it is and how?
推荐答案
SDCC是在那里,和gcc-4.6.2不编译就好了要么。好吧,如果你问它坚持迂腐的标准。
与 -std = C99 -pedantic
编译(或 -std = C1X -pedantic
),海湾合作委员会发出
Compiling with -std=c99 -pedantic
(or -std=c1x -pedantic
), gcc emits
warning: invalid use of structure with flexible array member
and clang-3.0 behaves similarly, its warning is slightly more informative:
warning: 'STRLIST_ENTRY' may not be used as an array element due to flexible array member
The standard prohibits that in 6.7.2.1 (3):
gcc和铿锵允许有结构
s的灵活数组成员结构
取值成员或数组作为一个扩展。该标准禁止的,因此,使用code,它是不可移植的,和每一个编译器是它的权利范围内拒绝code。
链接的问题是不相关的,它是关于不给一个警告,如果结构
具有灵活数组成员被初始化为自动,这是不容许每标准(但SDCC和其他人接受为扩展名)。
这篇关于SDCC不接受code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!