integer sizes

Jason House jason.james.house at gmail.com
Mon May 28 09:48:47 PDT 2007


Once upon a time, I thought I read that D was trying to clean up 
confusion of integer sizes, for example, this link 
http://www.digitalmars.com/d/type.html gives specific sizes that match a 
typical x86 machine.

Now that I'm developing for both 32bit and 64bit systems, I start to 
wonder what to type by default so that it's efficient on all the machines.

When I read http://www.digitalmars.com/d/portability.html, I see what I 
started with in this e-mail is wrong.  Integral sizes could be 
increased.  Does that mean sizeof(int) and sizeof(long) will ever match? 
  Or does that mean that if sizeof(int) increases, so will long and 
cent?    I don't know about others, but having sizeof(cent) != 128 seems 
really strange, even if it is a hypothetical feature.

I see that size_t and ptrdiff_t represent an integer of sufficient size 
to span the address space.  There's no types for natively sized 
integers.  Is it safe/best to assume that int is of native size?  Should 
I start adding my own alias for native integers?  (maybe nint)

I guess I sort of like the idea of int is always a native size and then 
having specific types such as int32, int64, etc...  I'm considering 
adding code which is very specific to integral sizes...  Depending of 
the case, I'd need to store anywhere between 49 and 361 bits.  When I 
start exceeding supported sizes, I have to start adding tricks...  I'd 
like to get it right for each machine.


More information about the Digitalmars-d-learn mailing list