Article View: comp.std.c
Article #202Re: Typedef Problem
From: Norman Diamond
Date: Sun, 12 Apr 1992 09:01
Date: Sun, 12 Apr 1992 09:01
43 lines
2902 bytes
2902 bytes
In article <1992Mar28.153738.20577@mcshh.Hanse.DE> buster@mcshh.Hanse.DE (Andreas Burmester) writes: >To handle strings, I've typedefed > typedef char CA[]; >and ran into a problem, I could track down to these definitions: >(0) CA s0 = "string 0"; >(1) CA s1 = "s1"; >(2) CA s2 = "this is string 2"; >The translator passes (0) and (1), while at (2), it complains >that "The initializer length exceeds the aggregate length." A >closer inspection reveals already at (1) things go (at least for >me) unexpected ways: There are 9 bytes allocated for s1 - note, >that strlen(s0) == 9 ! >It's obvious that, having processed (0), CA is 'retypdefed' to >char CA[9]. Then the initializer of s2 is indeed too long. My understanding of "Array declarators" (ANSI 3.5.4.2) is that the type CA is an array type and is an incomplete type. [3.5.4.2 is missing from the index for "type, incomplete" in the last draft edition.] My understanding of "Initialization" (ANSI 3.5.7) is that when an array of unknown size is initialized, the array is the one in the declarator. The array whose size is determined by the number of initializers, and which no longer has incomplete type, is the one in the declarator. This would be s0, s1, or s2. I don't believe that it would be CA. "Types" (ANSI 3.1.2.5) says that an array type of unknown size is completed, for an identifier of that type, by specifying the size in a later declaration. Unfortunately, this wording helps cloud things. I think that "an identifier OF that type" does not necessarily mean an identifier that IS the type, so my personal interpretation (as just given) seems possible. However, an array type of unknown size can be completed in some cases without even having an identifier, so I think that the wording cannot be taken literally. Therefore I'd advise getting an interpretation ruling. [Personal opinion only.] >The compiler, to name it, is ECO-C, a pre-ANSI translator. [And to repeat your note] >that strlen(s0) == 9 ! This topic is not suitable for comp.std.c, but your compiler was broken even under pre-ANSI common practices. sizeof s0 was 9 but strlen(s0) was 8. -- Norman Diamond diamond@jit081.enet.dec.com If this were the company's opinion, I wouldn't be allowed to post it. "Yeah -- bad wiring. That was probably it. Very bad."
Technical Details
Message-ID:
<1992Apr12.090149.11782@jrd.dec.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!decwrl!pa.dec.com!jrdzzz.jrd.dec.com!jit345.bad.jit.dec.com!diamondReferences:
<1992Mar28.153738.20577@mcshh.Hanse.DE>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c Path: arc1-ca.pugleaf.net!sparky!uunet!decwrl!pa.dec.com!jrdzzz.jrd.dec.com!jit345.bad.jit.dec.com!diamond From: diamond@jit345.bad.jit.dec.com (Norman Diamond) Subject: Re: Typedef Problem Message-ID: <1992Apr12.090149.11782@jrd.dec.com> Sender: usenet@jrd.dec.com (USENET ACCOUNT) Nntp-Posting-Host: jit345 Reply-To: diamond@jit.dec.com (Norman Diamond) Organization: Digital Equipment Corporation Japan , Tokyo References: <1992Mar28.153738.20577@mcshh.Hanse.DE> Date: Sun, 12 Apr 92 09:01:49 GMT Lines: 43