[5.10] Native types can't be used with pointers
Re: [5.10] Native types can't be used with pointers
No, when constructing a structure you need to know the whole size of it when EndStructure is called. It's the same in C/C++ for example and changing that will be very wierd and will have serious side effects (like SizeOf() being broken, OffsetOf() as well etc).
- Psychophanta
- Always Here
- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
Re: [5.10] Native types can't be used with pointers
Of course.
But please take in account if you forbid all types for pointers inside structures, then will be problems for some programs. This would suppose a regression!
But please take in account if you forbid all types for pointers inside structures, then will be problems for some programs. This would suppose a regression!
Last edited by Psychophanta on Thu Jan 17, 2013 2:00 pm, edited 1 time in total.
Re: [5.10] Native types can't be used with pointers
Only native type are forbidden, please read my posts more carefully, thanks.
- Psychophanta
- Always Here
- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
Re: [5.10] Native types can't be used with pointers
Oh, not enougth descriptive to me some of your posts, what a scare!.
Agree now! and tx
Agree now! and tx
Re: [5.10] Native types can't be used with pointers
Taken to long to find the old discussion about the topic with
not defined structures used with pointers in structures,
but finally i have found it ... even so this topic is now finished
here it is:
http://www.purebasic.fr/english/viewtop ... 7&p=400211
MFG PMV
not defined structures used with pointers in structures,
but finally i have found it ... even so this topic is now finished
here it is:
http://www.purebasic.fr/english/viewtop ... 7&p=400211
MFG PMV
-
- Enthusiast
- Posts: 542
- Joined: Tue Apr 24, 2012 5:08 pm
- Location: Ontario, Canada
Re: [5.10] Native types can't be used with pointers
Sigh!!!!! This whole discussion is a waste of bandwidth.
A pointer is just a pointer to a location in memory, and there's no universal law that says it has to be defined in a particular way. Every language I've ever worked with (and that's a lot) has had its own rules regarding pointers. Some are strictly typed, others are loosely typed, and others are not typed at all.
If PB forbids the use of native types with pointers, then get over it. That's just the way the language works. And if one feels that this feature is needed for documentation purposes, then use comments, that's what they're for.
Personally, I like PB pointers just the way they are.
A pointer is just a pointer to a location in memory, and there's no universal law that says it has to be defined in a particular way. Every language I've ever worked with (and that's a lot) has had its own rules regarding pointers. Some are strictly typed, others are loosely typed, and others are not typed at all.
If PB forbids the use of native types with pointers, then get over it. That's just the way the language works. And if one feels that this feature is needed for documentation purposes, then use comments, that's what they're for.
Personally, I like PB pointers just the way they are.
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
~ Spike Milligan
- Psychophanta
- Always Here
- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
Re: [5.10] Native types can't be used with pointers
I like it.BorisTheOld wrote:For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string
It goes now to my collection.

Re: [5.10] Native types can't be used with pointers
I would like a little more, but we can go by with what we have.BorisTheOld wrote: Personally, I like PB pointers just the way they are.
The biggest shortcoming I often encounter is this: you cannot increment a pointer value in an expression and use the resulting new address. You need to alter the value of the pointer variable permanently and then assign the value.
Code: Select all
*x.Integer
(*x + 2)\i = 10 ; we don't have this (add 2 to the pointer and store 10 at the resulting address)
There are other things but those would require a lot more work to be implemented, probably not worth it.
"Have you tried turning it off and on again ?"
A little PureBasic review
A little PureBasic review
Re: [5.10] Native types can't be used with pointers
Using pointers automatically as arrays (like C) would be cool:luis wrote:The biggest shortcoming I often encounter is this: you cannot increment a pointer value in an expression and use the resulting new address. You need to alter the value of the pointer variable permanently and then assign the value.
It would be nice. You can do it in other ways (the quickest making a copy of the pointer an alter that one) but it's something I miss.Code: Select all
*x.Integer (*x + 2)\i = 10 ; we don't have this (add 2 to the pointer and store 10 at the resulting address)
Code: Select all
*x.Integer = AllocateMemory( 10 * Sizeof(Integer) )
If *x
*x[0]\i = 10
*x[5]\i = 12
EndIf
Code: Select all
Macro DefPointerArray( __array_name__, __array_type__, __member_name__=mem )
Structure __array_name__
__member_name__.__array_type__#[0]
EndStructure
EndMacro
DefPointerArray(ByteArray , b, b)
DefPointerArray(AsciiArray , a, a)
DefPointerArray(CharacterArray, c, c)
DefPointerArray(WordArray , w, w)
DefPointerArray(UnicodeArray , u, u)
DefPointerArray(LongArray , l, l)
DefPointerArray(IntegerArray , i, i)
DefPointerArray(FloatArray , f, f)
DefPointerArray(DoubleArray , d, d)
DefPointerArray(QuadArray , q, q)
DefPointerArray(StringArray , s, s)
Debug "--------------------------------------------------------"
*p1.LongArray = AllocateMemory(10 * SizeOf(Long))
If *p1
For i = 0 To 9 : *p1\l[i] = i : Next
For i = 0 To 9 : Debug *p1\l[i] : Next
EndIf
Debug "--------------------------------------------------------"
*p2.ByteArray = *p1
If *p2
For i = 0 To 39 : a$ + Chr( *p2\b[i] + '0' ) + "," : Next
Debug a$
EndIf
Debug "--------------------------------------------------------"
Structure myPoint
x.l
y.l
EndStructure
DefPointerArray(myPointArray,myPoint)
*pt.myPointArray = AllocateMemory( 3 * SizeOf(myPoint) )
If *pt
*pt\mem[0]\x = 10
*pt\mem[0]\y = 20
*pt\mem[1]\x = 60
*pt\mem[1]\y = 70
*pt\mem[2]\x = 110
*pt\mem[2]\y = 120
*ptLong.LongArray = *pt
For i = 0 To 5 : Debug *ptLong\l[i] : Next
EndIf
Debug "--------------------------------------------------------"
DefPointerArray(Str3Arr,s{3})
*s.Str3Arr = AllocateMemory( 3 * 3 * SizeOf(Character) )
If *s
*s\mem[0] = "abc"
*s\mem[1] = "def"
*s\mem[2] = "ghi"
*c.CharacterArray = *s
For i = 0 To 8 : Debug Chr( *c\c[i] ) : Next
EndIf
Re: [5.10] Native types can't be used with pointers
Yes, this was one the other thing I was thinking about but didn't mention because I believe there can be hope for my first wish but this second one is something I don't see comingDanilo wrote: Using pointers automatically as arrays (like C) would be cool:

The idea of using a structure to "jump" the right amount for the offset like C does natively based on the pointed data type is certainly interesting, problem is you still have to specify the underlying field
*p1\l = i
instead of
*p1 = i
and this kills the magic for me.
But thanks for the nice example

"Have you tried turning it off and on again ?"
A little PureBasic review
A little PureBasic review
Re: [5.10] Native types can't be used with pointers
luis wrote:The idea of using a structure to "jump" the right amount for the offset like C does natively based on the pointed data type is certainly interesting, problem is you still have to specify the underlying field
*p1\l = i
instead of
*p1 = i
and this kills the magic for me.
The reason for that is the topic name: "[5.10] Native types can't be used with pointers".

You can only use structures with PB-Pointers, so even if they would add the auto-array-dereferencing for pointers,
you would need to write something like:
Code: Select all
*p1[i]\l = i
Code: Select all
*p1[i]\l = i ; PB way if they would enable it
*p1\l[i] = i ; using DefPointerArray
Code: Select all
*pt.myPoint = AllocateMemory( 3 * SizeOf(myPoint) )
If *pt
*pt[0]\x = 10
*pt[0]\y = 20
*pt[1]\x = 60
*pt[1]\y = 70
*pt[2]\x = 110
*pt[2]\y = 120
Code: Select all
*pt.myPointArray = AllocateMemory( 3 * SizeOf(myPoint) )
If *pt
*pt\mem[0]\x = 10
*pt\mem[0]\y = 20
*pt\mem[1]\x = 60
*pt\mem[1]\y = 70
*pt\mem[2]\x = 110
*pt\mem[2]\y = 120
Re: [5.10] Native types can't be used with pointers
Psychophanta wrote:I like it.BorisTheOld wrote:For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string
It goes now to my collection.
... it doesn't make any sense to me

Caesar was stabbed not hanged...
Maybe I just don't understand it...
I am to provide the public with beneficial shocks.
Alfred Hitshock
Re: [5.10] Native types can't be used with pointers
Yes, can someone please explain what the heck this means

For ten years Caesar ruled with an iron hand. Then with a wooden foot, and finally with a piece of string.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
-
- 666
- Posts: 1033
- Joined: Mon Sep 01, 2003 2:33 pm
Re: [5.10] Native types can't be used with pointers
You have to be a fan of "The goons" to understand
Spike Milligan's sense of humour was unique to say the least 


- Psychophanta
- Always Here
- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
Re: [5.10] Native types can't be used with pointers
You can also do this slow and ugly way:
Wrote nothing , grrr, it does not work
Wrote nothing , grrr, it does not work
Last edited by Psychophanta on Fri Jan 18, 2013 8:47 pm, edited 1 time in total.