[Gambas-user] Adding unsigned byte value to Pointer

Jussi Lahtinen jussi.lahtinen at gmail.com
Mon Mar 20 22:32:16 CET 2023


Brian is right, this should work. Pointer is just an unsigned integer with
size of 32 or 64 bits depending on the system.

Jussi

On Mon, Mar 20, 2023 at 11:10 PM Brian G <brian at westwoodsvcs.com> wrote:

> I Hate to disagree, but an unsigned value added to a pointer is just as
> valid as any other type of value added to a pointer. A pointer is
> essentially an unsigned value in this context, if I can Add an integer, or
> long why not any other integer value type...
>
> It is inconsistant to fail, as I can add a byte value or short value to a
> long value..... so there is automatic type conversion taking place. in
> those cases..., Why not then for byte and short values????
>
> Of course as you point out I can force the type conversion, but why?
>
> The byte and short just have to be added to the automatic type conversion
> to Pointer, as int and long already are.
>
> "Failure is the key to success;
>  each mistake teaches us something"  .. Morihei Ueshiba
> Brian G
>
> ----- On Mar 20, 2023, at 11:10 AM, T Lee Davidson
> t.lee.davidson at gmail.com wrote:
>
> > 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
> >
> >
> > ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20230320/599fae46/attachment-0001.htm>


More information about the User mailing list