integer sizes

torhu fake at address.dude
Mon May 28 13:32:14 PDT 2007


Jason House wrote:
> Rioshin an'Harthen wrote:
>> So if you need a specific bitsize for an integral type, use the standard 
>> byte,
>> short, int, long, cent, or their unsigned variants, while if you need 
>> the correct
>> native type use ptrdiff_t for signed values and size_t for unsigned.
> 
> I believe there's some intel machines with have 64 bit pointers but 32 
> bit integers.  I'd assume that size_t would be 64 bits, but the 
> desirable size for integers would still be 32 bits.  Using size_t in 
> that scenario would be incorrect.

The C99 stdint.h header is available in both Phobos and Tango.  But even 
the GDC Phobos version of the std.stdint only seems to have been made to 
work with x86, x86_64, and PPC.  Only the pointer-sized types vary in 
size.  So you'd probably have to put some static asserts in your code no 
matter what.  Just in case they forget to update the file when gdc is 
ported to a new platform.

Docs:
http://www.digitalmars.com/d/phobos/std_stdint.html
http://en.wikipedia.org/wiki/Stdint.h

Maybe you can use the int_fast32_t type or something of that sort.  But 
it's not even guaranteed to be the fastest type on any given platform.


More information about the Digitalmars-d-learn mailing list