I'm finding it more useful (than not) to have pointers with types -- even if those types are ignored.
For instance, if I have a *pt.b I know that the pointer is going to point to a byte -- internally, I know it is ignored; but reading code, it's nice to read what it thinks it should be. A pointer to a non-native type still points to an address in memory -- but we allow that. Just for readability, with a note "the type is actually ignored for all pointers"
5.20b2, pointers vs. native types.
Re: 5.20b2, pointers vs. native types.
For this point, there are the Structurs: Byte, Ascii, Character, Long ....jassing wrote:if I have a *pt.b I know that the pointer is going to point to a byte
the you can read it too:
Code: Select all
Structure Test
*Pointer.Byte
EndStructure
Define Value.b = 45
Define Test.Test
Test\Pointer = @Value
Debug Test\Pointer\b
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: 5.20b2, pointers vs. native types.
...well, what you really need to do is postfix and/or prefix your var names, common practice in most languages.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: 5.20b2, pointers vs. native types.
This "feature" has just been removed, so I doubt is coming back.jassing wrote:I'm finding it more useful (than not) to have pointers with types -- even if those types are ignored.
As already suggested, just use a meaningful prefix.
Because there is a reason. It permits to access memory at different offsets from the base address of the pointer specifying a structure's field.jassing wrote: A pointer to a non-native type still points to an address in memory -- but we allow that.
For a native type you can just use Peek*() and if you don't want the function overhead you can use the corresponding structure (Integer for .i and so on).
"Have you tried turning it off and on again ?"
A little PureBasic review
A little PureBasic review
Re: 5.20b2, pointers vs. native types.
Yes yes, hungarian notation.. yes yes.... still I found it useful.IdeasVacuum wrote:...well, what you really need to do is postfix and/or prefix your var names, common practice in most languages.
Re: 5.20b2, pointers vs. native types.
A pointer in PB is a native type like long, float, integer, ...
It is just not declared with a dot, but a star at the beginning.
If you declare a variable as a pointer and a word, it is like
declaring a variable as a integer and a word.
It just has worked because the compiler ignores the 2nd
declaration if it is declared as a pointer, but that is bad
behavior and was discussed a few times here and in
the other forums. ... at the end it is up to Fred how
it works or doesn't work. As i remember (is a long
time ago), Fred replied that it shouldn't be used ... so
it was just a matter of time till he "fixed" it.
PB uses pointers like integers, as long as they doesn't
have a structure. If they have, the pointer is accessible
like a structured variable. The only difference is, that
you have to deal with the blank memory for the structure
while PB manages the memory of a normal (not pointer)
structured variable itself and you just have to use
the fields.
As a side note, a month ago or less .. i have seen a
post from freak with a variable declared with a pointer
and another native type.
But no liability assumed!
MFG PMV
It is just not declared with a dot, but a star at the beginning.
If you declare a variable as a pointer and a word, it is like
declaring a variable as a integer and a word.

It just has worked because the compiler ignores the 2nd
declaration if it is declared as a pointer, but that is bad
behavior and was discussed a few times here and in
the other forums. ... at the end it is up to Fred how
it works or doesn't work. As i remember (is a long
time ago), Fred replied that it shouldn't be used ... so
it was just a matter of time till he "fixed" it.

PB uses pointers like integers, as long as they doesn't
have a structure. If they have, the pointer is accessible
like a structured variable. The only difference is, that
you have to deal with the blank memory for the structure
while PB manages the memory of a normal (not pointer)
structured variable itself and you just have to use
the fields.
As a side note, a month ago or less .. i have seen a
post from freak with a variable declared with a pointer
and another native type.

But no liability assumed!

MFG PMV
Re: 5.20b2, pointers vs. native types.
Yeah, I had many thousands of prototypes to edit because of this.
(*mypointer) leaves me guessing months later and I hate Hungarian notation, so no prefix stuff.
I took advantage of the decorated pointer(*mypointer.d) to tell me the underlying native type via the Context help.
No harm no fouls.
Now I have to add and carry type information with the variable names, (*mypointer_d), but not (*mypointer_d.i) which is superfluous.
So, the compromise is replace the '.' with an '_' and carry on.
(*mypointer) leaves me guessing months later and I hate Hungarian notation, so no prefix stuff.
I took advantage of the decorated pointer(*mypointer.d) to tell me the underlying native type via the Context help.
No harm no fouls.
Now I have to add and carry type information with the variable names, (*mypointer_d), but not (*mypointer_d.i) which is superfluous.
So, the compromise is replace the '.' with an '_' and carry on.

Code: Select all
;; FROM PB 5.0 code:
PrototypeC.l x(h.l,cp.u,*type.u,*points.i,*ti.d,*to.d,*vi.d,*vo.d)
;; TO PB 5.1 code:
PrototypeC.l x(h.l,cp.u,*type_u,*points_i,*ti_d,*to_d,*vi_d,*vo_d)
;; Or
PrototypeC.l x(h.l,cp.u,*type.unicode,*points.integer,*ti.double,*to.double,*vi.double,*vo.double)
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: 5.20b2, pointers vs. native types.
For what its worth, I use a suffix: 2b 2d 2f 2i 2q etc.
I find the .f .d etc. somewhat confusing, when used with pointers; just my humble opinion.
I find the .f .d etc. somewhat confusing, when used with pointers; just my humble opinion.
DE AA EB