From: Gabriel Kerneis <kerneis@pp...> - 2009-06-18 06:14:25
On Wed, Jun 17, 2009 at 02:30:07PM -0400, Divya Krishnan wrote:
> Is there an appropriate API in cil that when passed a type like say a
> struct/union will return the correct size of that type as an integer
> value. The one I could find was : val sizeOf :
> typ<http://manju.cs.berkeley.edu/cil/api/Cil.html#TYPEtyp>-> exp
> <http://manju.cs.berkeley.edu/cil/api/Cil.html#TYPEexp> but this
> returns an exp.
Looking for "sizeof" in the Cil API documentation, first hit:
CIL is configured at build-time with the sizes and alignments of the underlying
compiler (GCC or MSVC). CIL contains functions that can compute the size of a
type (in bits) Cil.bitsSizeOf, the alignment of a type (in bytes)
Cil.alignOf_int, and can convert an offset into a start and width (both in
bits) using the function Cil.bitsOffset. At the moment these functions do not
take into account the packed attributes and pragmas.
val bitsSizeOf : typ -> int
The size of a type, in bits. Trailing padding is added for structs and arrays.
Raises Cil.SizeOfError when it cannot compute the size. This function is
architecture dependent, so you should only call this after you call
Cil.initCIL. Remember that on GCC sizeof(void) is 1!
Get latest updates about Open Source Projects, Conferences and News.