Today, an Integer is the same as Int32. When Xojo moves to 64-bit, an Integer will be Int64, yes? So how can I tell the size of an Integer, for example, if I want to create a library that return the correct result on either 32- or 64-bit apps?
I ask because I’m introducing a function that will return the maximum value of an Integer. Right now, that’s &h7FFFFFFF, but eventually it will be &h7FFFFFFFFFFFFFFF.
I believe Xojo does not have a sizeof(), but it’s documented that on 32 systems Integer is 32 bit signed and in the future 64 bit systems it will be 64 bit signed, as a workaround you could set a constant based on #if Target64bit
“The Integer type is an alias to the platform’s native signed integer type.
On 32-bit builds, this ends up being SInt32 and on 64-bit builds this ends up being SInt64.”.
This is a case where there are really two answers. I’d have used Target64Bit, but that was introduced after the earliest supported version of Real Studio (this is for MacOSLib), so I ended up with a version of Brad’s code:
Protected Function NSIntegerMax() As Integer
static r as Integer
static needsCalc as boolean = true
if needsCalc then
dim n64 as Int64 = &h7FFFFFFFFFFFFFFF
r = n64
if n64 <> r then
r = &h7FFFFFFF
end if
needsCalc = false
end if
return r
// This is a method and not a constant because it will be a different value under 32-bit and 64-bit.
// Would use Target64Bit here but that is not supported in 2011r1. Otherwise, the code would look like this:
'#if Target64Bit
'return &h7FFFFFFFFFFFFFFF
'#else
'return &h7FFFFFFFF
'#endif
End Function