int always 32 bits on all platforms?

AJ aj at nospam.net
Wed Oct 21 22:41:42 PDT 2009


"Nick Sabalausky" <a at a.a> wrote in message 
news:hbonj3$u34$1 at digitalmars.com...
> "AJ" <aj at nospam.net> wrote in message news:hboa9p$5md$1 at digitalmars.com...
>>
>> "Walter Bright" <newshound1 at digitalmars.com> wrote in message 
>> news:hbo5il$2snd$5 at digitalmars.com...
>>> AJ wrote:
>>>> How can/does D guarantee that "int" will always be 32 bits on all 
>>>> platforms?
>>>
>>> The implementation on a platform must implement it that way.
>>>
>>>> Does this mean that D won't work on some platforms?
>>>
>>> You can make anything work on any platform
>>
>> How do you make ABC below work on a platform that requires 32-bit 
>> integers to be aligned on 32-bit boundaries while keeping the layount and 
>> size of ABC the same as on a platform that has no such alignment 
>> requirement?
>>
>> struct ABC
>> {
>>    byte a;
>>    int b; // may be improperly aligned on some platforms
>>    int64 c; // same issue
>> };
>>
>>
>
> It can be done by using bitmasks and bit shifting on every access.
>

I had a feeling I was delving into "dangerous territory" (read, way too low 
level for me, but I wonder what the possibilities are). I have a feeling 
that I may be wanting hardware standardization because it can't be "solved" 
at the language level (?). I don't understand how using bitmasks and bit 
shifting on every access would work, the plausibility of it, and the cost 
(in execution time) of doing so. 





More information about the Digitalmars-d mailing list