home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 16902 < prev    next >
Encoding:
Internet Message Format  |  1992-11-20  |  2.1 KB

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