[Implemented] Suggestion to avoid a PB incoherence

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

[Implemented] Suggestion to avoid a PB incoherence

Post by Psychophanta »

Code: Select all

*var2.b=AllocateMemory(100); *var2 is a pointer (i.e. in a 32 bit architecture *var2 is a long -32 bit- ), which is suposed to point to a byte variable.
*var3.s=AllocateMemory(100); *var3 is a pointer (i.e. in a 32 bit architecture *var3 is a long -32 bit- ), which is suposed to point to a string variable.
As you can see I can not define a pointer to a string and assign it a pointer value :o

The idea to solve it might be to allow pointers to strings normally, but internally treat them as *var.c.
This would solve the incoherence and at the same time it would not touch anything in PB.



Another related point is:
At the PB manual is written:
assigning a type to a pointer (*Pointer.l , *Pointer.b …) makes no sense
The point to understand here is that there are no fields inside native types like .l or .b, so why would you make a pointer to such a type? Only structured types, user or native, make sense.

But well; It also makes sense for standard native types just for readability.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

The string problem is a reported bug, pointer to string simply doesn't work all right in PB. (Fred said he's "looking".)
It also makes sense for standard native types just for readability.
Well, I think it looks horrible. :wink:
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Trond wrote:
It also makes sense for standard native types just for readability.
Well, I think it looks horrible. :wink:
Readability has nothing to do with beauty.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Psychophanta wrote:
Trond wrote:
It also makes sense for standard native types just for readability.
Well, I think it looks horrible. :wink:
Readability has nothing to do with beauty.
If I look away in horror, I can't read it!
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Horrible or not, readability means in this case to know what is pointed by a pointer variable when reading a code.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

In my opinion, if you can't access it, it doesn't matter what it is.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Trond wrote:In my opinion, if you can't access it, it doesn't matter what it is.
Can't access it???, ermh..., i think we are not talking about the same thing :?
Read above.
Why do you say can't access?
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

With *Pointer.b you can't access the byte, so it could be an elephant and I wouldn't care.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Trond wrote:With *Pointer.b you can't access the byte, so it could be an elephant and I wouldn't care.
I don't see the point, that's wrong.
The ususal way to access is PeekB(*Pointer.b).
Sorry but this discussion is void, or i miss something :o
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

If you need to access it, it's much faster to do *Byte.Byte\b than Peek(). The only reason for Peek() in that context is when you, for some strange reason declared a pointer to .b instead of .Byte.

It really doesn't make sense to use a slower method, when you have proper, faster method available.
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

An interesting thread:
http://www.purebasic.fr/english/viewtopic.php?t=22242

There is an inconsistency with strings in PB when dealing with pointers because of the way the strings are handled internally. Basically when you define a string like 'MyString.s' you are actually returned a pointer pointing to the string buffer. But it's all handled automagically without you knowing.

Have a search, there are lots of threads detailing this.

Plus (just for Trond) i have all this fully clarified in my book with a whole section dedicated to pointers and PB. :wink:
Psychophanta wrote:But well; It also makes sense for standard native types just for readability.
No it doesn't. :wink:
--Kale

Image
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Kale wrote:There is an inconsistency with strings in PB when dealing with pointers because of the way the strings are handled internally.
Sorry, but i must warn this http://www.purebasic.fr/english/viewtopic.php?t=22709 is called bug, not simple inconsistence.
And surely it would be solved if every *whatever.s was converted to *whatever.c in compilation time (this is the reason of be of this thread -read first post- ).
About readability it is explained above. :wink:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

And surely it would be solved if every *whatever.s was converted to *whatever.c in compilation time
Not really.

If everything was working correctly, these two would work the same:

Code: Select all

*String.s = "Test"
*Char.c = @"Test"
Of course, if you convert the *String.s to *String.c then it won't work the same any more.


Edit:
assigning a type to a pointer (*Pointer.l , *Pointer.b …) makes no sense
It makes sense for *String.s.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

@Trond, i don't know if you don't read or don't understand or what the hell... and sorry...
surely it would be solved if every *whatever.s was converted to *whatever.c in compilation time
That is probably the cleanest solution to the current problem of pointers to strings like *var.s or *var$.

Code: Select all

*String.s = "Test"
should not work and it would not work if that solution was performed in PB.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

Psychophanta,

Given the code:

Code: Select all

*var3.s=AllocateMemory(100);
What should be returned by the following?

Code: Select all

len(*var3)
How would this be affected by Unicode and Ascii settings?
Post Reply