[Gambas-user] Adding unsigned byte value to Pointer

T Lee Davidson t.lee.davidson at gmail.com
Mon Mar 20 19:10:15 CET 2023


On 3/20/23 12:37, Brian G wrote:
> Should adding an unsigned byte value to a pointer work correctly.
> 
> It generates and error, not pointer
> All other integer types may be added to a pointer, and work correctly.

It seems logical that attempting to add an unsigned value to a Pointer would produce an error. However, Shorts are signed and 
also cannot be added to a Pointer. Keep in mind that Pointers, in Gambas, are unique data types.

[code]
' Gambas module file

Public Sub Main()

   Dim pPointer As Pointer
   Dim bByte As Byte = 255
   Dim iShort As Short = bByte
   Dim iInt As Integer = bByte
   Dim iLong As Long = bByte

   ' Print CPointer(bByte) 'Type mismatch: wanted Pointer, got Byte instead
   ' Print CPointer(iShort) 'Type mismatch: wanted Pointer, got Short instead
   Print CPointer(iInt)
   Print CPointer(iLong)
   Print

   ' Print pPointer + bByte 'Type mismatch: wanted Pointer, got Byte instead
   ' Print pPointer + iShort 'Type mismatch: wanted Pointer, got Short instead
   Print pPointer + iInt
   Print pPointer + iLong
   Print

   Print pPointer + CInt(bByte)

End
[/code]


-- 
Lee



More information about the User mailing list