comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: C's sizeof
Date: Thu, 12 Apr 2012 18:24:31 -0400
Date: 2012-04-12T18:24:31-04:00	[thread overview]
Message-ID: <wccehrs6128.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: m2sjg8gbky.fsf@pushface.org

Simon Wright <simon@pushface.org> 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



  parent reply	other threads:[~2012-04-12 22:24 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-12 16:27 C's sizeof Simon Wright
2012-04-12 16:43 ` Adam Beneschan
2012-04-12 18:42   ` Simon Wright
2012-04-12 18:58     ` Adam Beneschan
2012-04-12 20:29       ` Simon Wright
2012-04-12 20:59       ` Jeffrey Carter
2012-04-12 22:24 ` Robert A Duff [this message]
2012-04-13  5:57   ` Simon Wright
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox