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

Everything else that doesn't fall into one of the other PB categories.
User avatar
le_magn
Enthusiast
Enthusiast
Posts: 277
Joined: Wed Aug 24, 2005 12:11 pm
Location: Italia

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

Post 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?
Image
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

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

Post 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.
User avatar
le_magn
Enthusiast
Enthusiast
Posts: 277
Joined: Wed Aug 24, 2005 12:11 pm
Location: Italia

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

Post 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 :)
Image
User avatar
jacdelad
Addict
Addict
Posts: 1992
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

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

Post by jacdelad »

Try the brand-new 6.21 Beta 2.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
Mijikai
Addict
Addict
Posts: 1517
Joined: Sun Sep 11, 2016 2:17 pm

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

Post by Mijikai »

Imho. this syntax would make sense if you could actually use it like this:

Code: Select all

*value.b = address
*value\b
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

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

Post 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?
User avatar
mk-soft
Always Here
Always Here
Posts: 6204
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

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

Post 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
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Mijikai
Addict
Addict
Posts: 1517
Joined: Sun Sep 11, 2016 2:17 pm

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

Post 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
User avatar
mk-soft
Always Here
Always Here
Posts: 6204
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

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

Post by mk-soft »

I think it's better to have to define the pointer type beforehand to avoid errors.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
le_magn
Enthusiast
Enthusiast
Posts: 277
Joined: Wed Aug 24, 2005 12:11 pm
Location: Italia

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

Post 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
Image
User avatar
mk-soft
Always Here
Always Here
Posts: 6204
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

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

Post 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)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
le_magn
Enthusiast
Enthusiast
Posts: 277
Joined: Wed Aug 24, 2005 12:11 pm
Location: Italia

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

Post 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
Image
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

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

Post 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.
User avatar
Mijikai
Addict
Addict
Posts: 1517
Joined: Sun Sep 11, 2016 2:17 pm

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

Post 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.
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

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

Post 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**
Post Reply