[vtkusers] Question about 64-bit ids and long

Mike Jackson mike.jackson at bluequartz.net
Tue Sep 23 11:04:29 EDT 2008


Mathieu Malaterre wrote:
> On Tue, Sep 23, 2008 at 4:39 PM, Nick Gnedin <gnedin at fnal.gov> wrote:
>   
>> Mathieu,
>>
>> Thank you so much for all your answers.
>>
>>     
>>> maybe, but that not the definition of vtkIdType. On 32bits, I want to
>>> be able to have vtkIdType of 64bits.
>>>       
>> Could you tell me why? I am just curious - I do not see a clear reason.
>>     
>
> I do not know why, that's the defined behavior IMHO. At least on linux
> (BIGMEM) you can address 4Gb even on 32bits system AFAIK.
>
>
>   
>> If long long works, then it is fine. I just thought that long, being a
>> standard type, is more portable. In fact, until very recently I thought that
>> long long is 128-bit on a 64-bit platform.
>>     
>
> sizeof(long long) returns 8 on my linux box (amd64)
>
>   
long is _bad_ IMHO because it can be different sizes on different 
platforms as you are finding out. Long Long is _usually_ safer but there 
are reasons not to use that either. Most projects like VTK and ParaView 
run tests to figure out the proper sizes of the primitives to use. You 
should use those where appropriate. I am not well versed in the Linux 
space but I have hit these 32bit/64 bit issues enough between all the 
places that I compile that I stay away from "long", use "long long" 
sparingly and try to rely on what the major frameworks are using as 
typedefs.

I think some history might be in order (Some one correct me where I am 
wrong).

In the 16bit days, int was 2 bytes, long int was 4 bytes and long long 
int was 8.

Then 32 bit computing came along and an int is now 4 bytes. Some 
compilers moved long int to 8, some did not for what ever reasons. So 
what happens is that typically if you are on a 32 bit machine then long 
is 4 bytes and if you are on a 64 bit machine long is 8 bytes. This can 
cause all sorts of portability issues. From all the compilers that I 
have seen, whether 32 or 64 bit, int always seems to be 4 bytes and long 
long always seems to be 8 bytes. Long is ambiguous and really should be 
avoided.

Those are just my opinions and 2 cents,.. well maybe 3 cents..
Mike



More information about the vtkusers mailing list