home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!gatech!usenet.ins.cwru.edu!agate!doc.ic.ac.uk!uknet!acorn!ixi!clive
- From: clive@x.co.uk (Clive Feather)
- Newsgroups: comp.lang.c
- Subject: Re: Is this ANSI?
- Message-ID: <1992Nov20.162121.3675@x.co.uk>
- Date: 20 Nov 92 16:21:21 GMT
- References: <9eRguB1w165w@quest.UUCP>
- Organization: IXI Limited, Cambridge, UK
- Lines: 51
-
- In article <9eRguB1w165w@quest.UUCP> srhqla!quest!kdq writes:
- > I'm working on an HP9000, in UNIX, using the native C compiler
- >which claims to be ANSI compliant. It appears to be, in most things,
- >even though you've got to jump through hoops to really get it into ANSI
- >mode with the correct ANSI includes.
-
- Funny - I just type "c89 prog.c -o prog" and it's perfect.
-
- > Here is (a simplified version of) the struct that the compiler
- > calls an error:
- >
- > struct FM
- > {
- > short data_len;
- > char data[]; /* This line is the kicker */
- > };
- >
- > As I recall, ANSI says this is legal,
-
- You recall wrong. This declaration gives "data" the 'incomplete type'
- "array (size unknown) of char". The standard says [6.5.2.1]:
- | A structure or union shall not contain a member with incomplete or
- | function type.
-
- A diagnostic is required in this situation. Any compiler failing to
- generate one is not ANSI/ISO compliant - ask for your money back.
-
- Note that both "char data [1]" and "char *data" are legal here, as they
- give "data" type type "array (size 1) of char" and "pointer to char"
- respectively. As a stand-alone declaration, the original line would also
- be permitted:
-
- char data [];
-
- /* Code accessing data in certain ways only */
-
- char data [10];
-
- /* More code */
-
- The code indicated by the first comment may take the address of data,
- and may use it in any way (such as subscripting it) that causes it to
- decay, via the Rule, into a pointer. It may *not*, however, pass it to
- "sizeof" or anywhere else that the standard requires a 'completed
- type'.
-
- --
- Clive D.W. Feather | IXI Limited | If you lie to the compiler,
- clive@x.co.uk | Vision Park | it will get its revenge.
- Phone: +44 223 236 555 | Cambridge CB4 4RZ | - Henry Spencer
- Fax: +44 223 236 550 | United Kingdom |
-