🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #1956

Re: question about an array of enum

#1956
From: Tim McDaniel
Date: Fri, 09 Nov 1990 16:16
40 lines
2356 bytes
Karl Heuer wrote:
> What this really implies is that, if bit arrays are ever supported,
> they won't fit cleanly into the existing language and hence will
> probably not support all the same features as "normal" arrays.

kdb@chinet.chi.il.us (Karl Botts) suggests that sizeof a hypothetical
bit type in C could include padding to the nearest byte.

> This is OK; sizeof produces the amount of storage needed to hold an
> object, not the actual size of the object.  I would expect sizeof
> applied to an array of 8 bits to also return 1, tho of course this
> would be implementation dependent.

While the bit 8-) about padding is true, there are other rules and
assumptions that would break.  Which of the following do you want to
break?  Consider the costs of not breaking on byte-addressed
architectures.

* sizeof array / sizeof array[0] is the number of elements in an array.
  (ANS C standard section 3.3.3.2, "Examples" subsection.)

* "void *" and "char *" have the same representation.
  (3.1.2.3, "Types".)

* a "void *" can store a pointer to any incomplete or object type.
  (3.2.2.3, "Pointers".)

* One of the operands to "[]" shall have type "pointer to object
  TYPE", and the result has type "TYPE".  "E1[E2]" is defined to be
  identical to "(*(E1+(E2)))".
  (3.3.2.1, "Array Subscripting".)
  (Consider the standard
     "for (i = 0; i < NUM; i++)"
  to
     "for (p = &a[0]; p < &a[NUM]; p++)"
  transformation.)
--
Tim McDaniel                 Applied Dynamics Int'l.; Ann Arbor, Michigan, USA
Work phone: +1 313 973 1300                        Home phone: +1 313 677 4386
Internet: mcdaniel@adi.com                UUCP: {uunet,sharkey}!amara!mcdaniel
Technical Details
Message-ID: <MCDANIEL.90Nov9111600@dolphin.adi.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!umich!sharkey!amara!mcdaniel
References: <9130019@hpavla.AVO.HP.COM> <MCDANIEL.90Nov6114504@dolphin.adi.com> <1990Nov06.200927.28712@dirtydog.ima.isc.com> <1990Nov08.025037.8594@chinet.chi.il.us>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!umich!sharkey!amara!mcdaniel
From: mcdaniel@adi.com (Tim McDaniel)
Newsgroups: comp.std.c
Subject: Re: question about an array of enum
Message-ID: <MCDANIEL.90Nov9111600@dolphin.adi.com>
Date: 9 Nov 90 16:16:00 GMT
References: <9130019@hpavla.AVO.HP.COM> <MCDANIEL.90Nov6114504@dolphin.adi.com>
 <1990Nov06.200927.28712@dirtydog.ima.isc.com>
 <1990Nov08.025037.8594@chinet.chi.il.us>
Sender: news@adi.COM
Organization: Applied Dynamics International, Inc.; Ann Arbor, Michigan, USA
Lines: 40
In-reply-to: kdb@chinet.chi.il.us's message of 8 Nov 90 02:50:37 GMT