Page 3 of 4
					
				Re: [5.10] Native types can't be used with pointers
				Posted: Thu Jan 17, 2013 1:54 pm
				by Fred
				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).
			 
			
					
				Re: [5.10] Native types can't be used with pointers
				Posted: Thu Jan 17, 2013 1:58 pm
				by Psychophanta
				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!
			 
			
					
				Re: [5.10] Native types can't be used with pointers
				Posted: Thu Jan 17, 2013 2:00 pm
				by Fred
				Only native type are forbidden, please read my posts more carefully, thanks.
			 
			
					
				Re: [5.10] Native types can't be used with pointers
				Posted: Thu Jan 17, 2013 2:03 pm
				by Psychophanta
				Oh, not enougth descriptive to me some of your posts, what a scare!.
Agree now! and tx
			 
			
					
				Re: [5.10] Native types can't be used with pointers
				Posted: Thu Jan 17, 2013 2:15 pm
				by PMV
				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
 
			 
			
					
				Re: [5.10] Native types can't be used with pointers
				Posted: Thu Jan 17, 2013 2:24 pm
				by BorisTheOld
				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.
			 
			
					
				Re: [5.10] Native types can't be used with pointers
				Posted: Thu Jan 17, 2013 2:29 pm
				by Psychophanta
				BorisTheOld wrote:For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string
I like it.
It goes now to my collection.  

 
			 
			
					
				Re: [5.10] Native types can't be used with pointers
				Posted: Thu Jan 17, 2013 2:38 pm
				by luis
				BorisTheOld wrote:
Personally, I like PB pointers just the way they are.
I would like a little more, but we can go by with what we have.
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)
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.
There are other things but those would require a lot more work to be implemented, probably not worth it.
 
			 
			
					
				Re: [5.10] Native types can't be used with pointers
				Posted: Fri Jan 18, 2013 4:29 pm
				by Danilo
				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.
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)
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.
 
Using pointers automatically as arrays (like C) would be cool:
Code: Select all
*x.Integer = AllocateMemory( 10 * Sizeof(Integer) )
If *x
    *x[0]\i = 10
    *x[5]\i = 12
EndIf
PB emulation:
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
				Posted: Fri Jan 18, 2013 6:10 pm
				by luis
				Danilo wrote:
Using pointers automatically as arrays (like C) would be cool:
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 coming 
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  
 
			 
			
					
				Re: [5.10] Native types can't be used with pointers
				Posted: Fri Jan 18, 2013 6:27 pm
				by Danilo
				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:
You would always need to use a structure member anyway, because pointers are only supported with structures, not simple types.
Code: Select all
*p1[i]\l = i ; PB way if they would enable it
*p1\l[i] = i ; using DefPointerArray
Native PB support would allow to write:
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
directly for complex structures, instead ugly:
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
				Posted: Fri Jan 18, 2013 7:33 pm
				by fsw
				Psychophanta wrote:BorisTheOld wrote:For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string
I like it.
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...
 
			 
			
					
				Re: [5.10] Native types can't be used with pointers
				Posted: Fri Jan 18, 2013 7:50 pm
				by skywalk
				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.
 
			 
			
					
				Re: [5.10] Native types can't be used with pointers
				Posted: Fri Jan 18, 2013 8:05 pm
				by LuCiFeR[SD]
				You have to be a fan of "The goons" to understand 

  Spike Milligan's sense of humour was unique to say the least 

 
			 
			
					
				Re: [5.10] Native types can't be used with pointers
				Posted: Fri Jan 18, 2013 8:13 pm
				by Psychophanta
				You can also do this slow and ugly way:
Wrote nothing , grrr, it does not work