From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,167fc3ed1f7df035 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.125.233 with SMTP id mt9mr18550pbb.5.1334262545019; Thu, 12 Apr 2012 13:29:05 -0700 (PDT) Path: r9ni48955pbh.0!nntp.google.com!news2.google.com!goblin3!goblin1!goblin.stu.neva.ru!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: C's sizeof Date: Thu, 12 Apr 2012 21:29:03 +0100 Organization: A noiseless patient Spider Message-ID: References: <10939468.224.1334249018393.JavaMail.geo-discussion-forums@yngq4> <11092332.346.1334257093663.JavaMail.geo-discussion-forums@ynhh34> Mime-Version: 1.0 Injection-Info: mx04.eternal-september.org; posting-host="dFCm8HWntFqmDIilBLqEJQ"; logging-data="15307"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18c+lh5z1zxOZ1yD34Sbbke0+NneHU+t0Q=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (darwin) Cancel-Lock: sha1:+GNEXuRJWcswh6kw3I1/Dw1XIpY= sha1:r2AzxC3kfjAn8w3On0Iy8Cu2mq8= Content-Type: text/plain; charset=us-ascii Date: 2012-04-12T21:29:03+01:00 List-Id: Adam Beneschan writes: > On Thursday, April 12, 2012 11:42:46 AM UTC-7, Simon Wright wrote: >> Adam Beneschan writes: >> >> > On Thursday, April 12, 2012 9:27:09 AM UTC-7, Simon Wright wrote: >> >> The (draft) ARM Annex B.3[1] says at para 73 - Note 7 - >> >> >> >> "To obtain the effect of C's sizeof(item_type), where Item_Type is >> >> the corresponding Ada type, evaluate the expression: >> >> size_t(Item_Type'Size/CHAR_BIT)." >> >> >> >> Should that not be >> >> >> >> size_t((Item_Type'Size + CHAR_BIT - 1)/CHAR_BIT) >> >> >> >> ? >> >> >> >> [1] http://www.ada-auth.org/standards/12rm/html/RM-B-3.html >> > >> > Does C even support types whose sizes aren't a multiple of a byte? If >> > it doesn't, then since B.3 is talking about the Ada type >> > "corresponding" to a C type, the question is probably moot. >> >> Doesn't B.3 apply to types with Convention => C? >> >> GNAT allows >> >> type N2 is range 0 .. Integer'Last - 1; >> pragma Convention (C, N2); >> >> and N2'Size is 31 ... > > Yeah, you're right. But then I don't think your formula would work > either: > > type N3 is range 0 .. 2**22 - 1; > pragma Convention (C, N3); > > and N3'Size is 22. But what would the sizeof() of the C type be? Hmm, not 3 I suspect (and not 2, either, which the ARM formula would give). Perhaps the compiler should make 'Size be 8, 16, 32, 64 ... if the convention implies it? but cf the K.2(225) definition of 'Size as [the size (in bits) that the implementation would choose for] a record component of [the subtype] when the record type is packed; and the fact that C does support struct components of non-byte-multiple sizes. Is sizeof more like the missing 'Object_Size attribute? GNAT makes 'Stream_Size 4 for both N2 and N3.