[Gambas-user] unsigned int datatype for external function
Jussi Lahtinen
jussi.lahtinen at gmail.com
Sun Jun 10 20:18:35 CEST 2018
Lee,
if you don't believe me try this:
Make a library with following code:
unsigned int TakeAndReturn(unsigned int value)
{
return value;
}
Then from Gambas:
Private Extern TakeAndReturn(value As Integer) As Integer In "libTest" '...
or what ever
Print Bin(TakeAndReturn(2 ^ 32), 32)
You get the expected value: 10000000000000000000000000000000
Then try it as long:
Private Extern TakeAndReturn(value As Long) As Long In "liblibTest"
If you don't get crash, you will get wrong result. However it might work
with small values.
Jussi
On Sun, Jun 10, 2018 at 8:48 PM, T Lee Davidson <t.lee.davidson at gmail.com>
wrote:
> On 06/10/2018 01:42 PM, Jussi Lahtinen wrote:
> > An integer type is obviously not wide enough.
> >
> >
> > It is. You need 32 bits and Gambas integer is 32 bits. Gambas just
> interprets/displays the most significant bit as sign bit.
> >
> >
>
> That means that the Gambas integer type is only 31 (+ 1) bits wide. Not
> wide enough to hold a 32-bit unsigned integer if the
> highest bit is reserved for the sign bit.
>
> So then, if it is wide enough as you say, how would one manage a 32-bit
> unsigned integer in a 32-bit signed datatype?
>
>
> --
> Lee
>
> ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20180610/8e96c863/attachment.html>
More information about the User
mailing list