Page 1 of 2

PB6.20+ Native types can't be used with pointers.

Posted: Sat Mar 22, 2025 7:33 pm
by le_magn
Hi all, in PB6.20 AND PB6.21Beta1 i get this error "Native types can't be used with pointers", at this line:

Code: Select all

InRange(*pTextRange.i, prop.i)
But with 6.12 it compile ok, is this normal?

Re: PB6.20+ Native types can't be used with pointers.

Posted: Sat Mar 22, 2025 7:52 pm
by Demivec
le_magn wrote: Sat Mar 22, 2025 7:33 pm Hi all, in PB6.20 AND PB6.21Beta1 i get this error "Native types can't be used with pointers", at this line:

Code: Select all

InRange(*pTextRange.i, prop.i)
But with 6.12 it compile ok, is this normal?
Yes it is normal. Just remove the native type on the pointer variable (i.e. the '.i' part). In previous versions of PureBasic having a native type didn't make sense and wasn't needed, because pointers always held an integer value, but no error was thrown. Now it throws an error.

Re: PB6.20+ Native types can't be used with pointers.

Posted: Sat Mar 22, 2025 8:30 pm
by le_magn
Demivec wrote: Sat Mar 22, 2025 7:52 pm Yes it is normal. Just remove the native type on the pointer variable (i.e. the '.i' part). In previous versions of PureBasic having a native type didn't make sense and wasn't needed, because pointers always held an integer value, but no error was thrown. Now it throws an error.
Ok thank's :)

Re: PB6.20+ Native types can't be used with pointers.

Posted: Sun Mar 23, 2025 7:01 am
by jacdelad
Try the brand-new 6.21 Beta 2.

Re: PB6.20+ Native types can't be used with pointers.

Posted: Sun Mar 23, 2025 10:05 am
by Mijikai
Imho. this syntax would make sense if you could actually use it like this:

Code: Select all

*value.b = address
*value\b

Re: PB6.20+ Native types can't be used with pointers.

Posted: Sun Mar 23, 2025 10:18 am
by Little John
jacdelad wrote: Sun Mar 23, 2025 7:01 am Try the brand-new 6.21 Beta 2.
What has changed in this respect in that version?

Re: PB6.20+ Native types can't be used with pointers.

Posted: Sun Mar 23, 2025 12:10 pm
by mk-soft
Mijikai wrote: Sun Mar 23, 2025 10:05 am Imho. this syntax would make sense if you could actually use it like this:

Code: Select all

*value.b = address
*value\b
PB Syntax

Code: Select all

Global bVal.b, *value.byte

*value = @bVal
*value\b = 10
Debug bVal

Re: PB6.20+ Native types can't be used with pointers.

Posted: Sun Mar 23, 2025 12:14 pm
by Mijikai
@mk-soft, thats how it currently works.
What is your point?

Mby this is more readable:

Code: Select all

Global.b a,*b

a = 123
*b = @a

Debug *b\b

Re: PB6.20+ Native types can't be used with pointers.

Posted: Sun Mar 23, 2025 12:38 pm
by mk-soft
I think it's better to have to define the pointer type beforehand to avoid errors.

Re: PB6.20+ Native types can't be used with pointers.

Posted: Sun Mar 23, 2025 1:08 pm
by le_magn
jacdelad wrote: Sun Mar 23, 2025 7:01 am Try the brand-new 6.21 Beta 2.
Same error with 6.21Beta2

Re: PB6.20+ Native types can't be used with pointers.

Posted: Sun Mar 23, 2025 3:44 pm
by mk-soft
le_magn wrote: Sat Mar 22, 2025 7:33 pm Hi all, in PB6.20 AND PB6.21Beta1 i get this error "Native types can't be used with pointers", at this line:

Code: Select all

InRange(*pTextRange.i, prop.i)
But with 6.12 it compile ok, is this normal?
Remove ".i"

Code: Select all

InRange(*pTextRange, prop.i)

Re: PB6.20+ Native types can't be used with pointers.

Posted: Sun Mar 23, 2025 5:59 pm
by le_magn
mk-soft wrote: Sun Mar 23, 2025 3:44 pm
Remove ".i"

Code: Select all

InRange(*pTextRange, prop.i)
[/quote]

:D Thanks MKSoft, but so far I can see that if I remove ā€˜.i’ I don't get the error (maybe I can't explain it well as I speak English very poorly), but I just wanted to know why with versions prior to 6.20 I don't get the error

Re: PB6.20+ Native types can't be used with pointers.

Posted: Sun Mar 23, 2025 8:12 pm
by Demivec
Mijikai wrote: Sun Mar 23, 2025 12:14 pm @mk-soft, thats how it currently works.
What is your point?

Mby this is more readable:

Code: Select all

Global.b a,*b

a = 123
*b = @a

Debug *b\b
How does your suggested method for pointer declarations know which structure is being referenced by the pointer?

Code: Select all

Structure Byte
  b.b
EndStructure 

Structure b
  b.i
  honey.b
EndStructure

;Global a.b, *b.Byte ;current syntax for pointer declarations
Global.b a,*b ;suggested modification to syntax for pointer declarations

a = 123
*b = @a

Debug *b\b
Now imagine hundreds of more structure definitions. IMHO the current method is clear and simple. If your suggestion was implemented you would require the compiler to guess what you intended instead of simply doing what you told it to do.

Re: PB6.20+ Native types can't be used with pointers.

Posted: Sun Mar 23, 2025 8:58 pm
by Mijikai
Demivec wrote: Sun Mar 23, 2025 8:12 pm How does your suggested method for pointer declarations know which structure is being referenced by the pointer?
First of all there is nothing wrong with how things currently work.
If someone wants to bring back this *pointer.i syntax for whatever reason i just suggest to make it useful in a different way.

Support all type variables for pointers and make them work like i showed in my examples.
Its simple if is .b with a *poiner its .Byte, .w is .Word and so on...

It would be shorter, cleaner and still very easy to understand.

Re: PB6.20+ Native types can't be used with pointers.

Posted: Sun Mar 23, 2025 10:26 pm
by Demivec
Mijikai wrote: Sun Mar 23, 2025 8:58 pm
Demivec wrote: Sun Mar 23, 2025 8:12 pm How does your suggested method for pointer declarations know which structure is being referenced by the pointer?
First of all there is nothing wrong with how things currently work.
If someone wants to bring back this *pointer.i syntax for whatever reason i just suggest to make it useful in a different way.

Support all type variables for pointers and make them work like i showed in my examples.
Its simple if is .b with a *poiner its .Byte, .w is .Word and so on...

It would be shorter, cleaner and still very easy to understand.
**Begin Soap Box warning**

IMHO, the current syntax is for dereferencing structured memory areas that the pointer is pointing to. There is nothing that deals with 'types', instead it only deals with fields of a structure. It is simple and concise.

I am always in favor of making things easier and shorter but your suggestion isn't really useful or cleaner though it is fractionally shorter. There's no real understanding given why one would have to access the value of a 'byte' pointed to with a pointer of type '.b' by using *ptr\b instead of *ptr. In the attempt to shorten things you are hiding the fact that you are dereferencing a Byte structure that has the field 'b.b'. It hides and confuses the fact that a pointer's value and what it references are different things.

Since using pointers is classified as an advanced topic I think your suggestion would only encourage a programmer to use pointers in a sloppy way that invites bugs.

**End Soap Box warning**