Page 1 of 1

5.20b2, pointers vs. native types.

Posted: Fri Jan 04, 2013 8:05 pm
by jassing
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"

Re: 5.20b2, pointers vs. native types.

Posted: Fri Jan 04, 2013 8:32 pm
by STARGĂ…TE
jassing wrote:if I have a *pt.b I know that the pointer is going to point to a byte
For this point, there are the Structurs: Byte, Ascii, Character, Long ....
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

Re: 5.20b2, pointers vs. native types.

Posted: Fri Jan 04, 2013 8:53 pm
by IdeasVacuum
...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.

Posted: Fri Jan 04, 2013 11:38 pm
by luis
jassing wrote:I'm finding it more useful (than not) to have pointers with types -- even if those types are ignored.
This "feature" has just been removed, so I doubt is coming back.
As already suggested, just use a meaningful prefix.
jassing wrote: A pointer to a non-native type still points to an address in memory -- but we allow that.
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.
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).

Re: 5.20b2, pointers vs. native types.

Posted: Fri Jan 04, 2013 11:57 pm
by jassing
IdeasVacuum wrote:...well, what you really need to do is postfix and/or prefix your var names, common practice in most languages.
Yes yes, hungarian notation.. yes yes.... still I found it useful.

Re: 5.20b2, pointers vs. native types.

Posted: Sat Jan 05, 2013 12:12 am
by PMV
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. :lol:

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. :mrgreen:
But no liability assumed! :wink:

MFG PMV

Re: 5.20b2, pointers vs. native types.

Posted: Sat Jan 05, 2013 12:47 am
by skywalk
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. :wink:

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)

Re: 5.20b2, pointers vs. native types.

Posted: Mon Jan 07, 2013 9:03 pm
by davido
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.