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.227.230 with SMTP id sd6mr314003pbc.8.1334269473041; Thu, 12 Apr 2012 15:24:33 -0700 (PDT) Path: r9ni49254pbh.0!nntp.google.com!news1.google.com!news2.google.com!news.glorb.com!news-out.readnews.com!news-xxxfer.readnews.com!panix!newsfeed-00.mathworks.com!nntp.TheWorld.com!.POSTED!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: C's sizeof Date: Thu, 12 Apr 2012 18:24:31 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 X-Trace: pcls6.std.com 1334269472 4739 192.74.137.71 (12 Apr 2012 22:24:32 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Thu, 12 Apr 2012 22:24:32 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:u+ZqR4DVrNRawGwN4wpb4VfN4do= Content-Type: text/plain; charset=us-ascii Date: 2012-04-12T18:24:31-04:00 List-Id: Simon Wright writes: > 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) > > ? I think it should be more like: pragma Assert(Item_Type'Base'Size mod CHAR_BIT = 0); pragma Assert(Item_Type'Size = Item_Type'Base'Size); size_of_item: constant size_t := size_t(Item_Type'Size/CHAR_BIT); pragma Assert(size_of_item*CHAR_BIT = Item_Type'Size); See Jeff Carter's comment. Maybe some of those asserts are overkill, but if you're interfacing to C, you don't want to mess around with subranges that C doesn't understand. - Bob