SDCC不接受code [英] sdcc not accepting code

查看:800
本文介绍了SDCC不接受code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有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不编译就好了要么。好吧,如果你问它坚持迂腐的标准。

SDCC is right there, and gcc-4.6.2 does not compile it "just fine" either. Well, if you ask it to adhere to the standard pedantically.

-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

和铛 - 3.0表现类似,它的预警稍微更多的信息:

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

该标准禁止在6.7.2.1(3):

The standard prohibits that in 6.7.2.1 (3):

一个结构体或联合体中不得含有不完整或函数类型的成员(因此,结构不得含有自己的实例,但可以包含一个指向自己的一个实例),但结构的最后一个成员与多个命名的成员可能有不完整的数组类型; 这样的结构(含可能递归任何工会的成员就是这样的结构)不得结构的成员或数组的元素。

A structure or union shall not contain a member with incomplete or function type (hence, a structure shall not contain an instance of itself, but may contain a pointer to an instance of itself), except that the last member of a structure with more than one named member may have incomplete array type; such a structure (and any union containing, possibly recursively, a member that is such a structure) shall not be a member of a structure or an element of an array.

(重点是我的)

gcc和铿锵允许有结构 s的灵活数组成员结构取值成员或数组作为一个扩展。该标准禁止的,因此,使用code,它是不可移植的,和每一个编译器是它的权利范围内拒绝code。

gcc and clang allow having structs with flexible array members as members of structs or arrays as an extension. The standard prohibits that, so code using that is not portable, and every compiler is within its rights to reject the code.

链接的问题是不相关的,它是关于不给一个警告,如果结构具有灵活数组成员被初始化为自动,这是不容许每标准(但SDCC和其他人接受为扩展名)。

The linked issue is not relevant, it is about not giving a warning if a struct with a flexible array member is instantiated as an automatic, which isn't allowed per the standard (but accepted by SDCC and others as an extension).

这篇关于SDCC不接受code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆