Support pointer (structure) as return value in procedures
Re: Support pointer (structure) as return value in procedure
It is a check during compile time...not runtime.
this check have only to do if there a structurepointer expected.
The i is a void pointer and need no check.
Open your mind and you understand it.
this check have only to do if there a structurepointer expected.
The i is a void pointer and need no check.
Open your mind and you understand it.
Belive! C++ version of Puzzle of Mystralia
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
Re: Support pointer (structure) as return value in procedure
IceSoft wrote:I dont want realy a functionality.
[...]
Thats all and it improve the reading of PureBasic source code too.
IceSoft wrote:Is is not for cosmetic. Never!
It is a feature which improve the compiler...if you make a type check:

so i will repeat it:
PMV wrote:You should try a OOP-Language.![]()
PB does only return a 32-Bit (or 64-Bit) value. PB does not know
what structure is behind the pointer. If you want such functionality,
there are a lot of OOP-Languages available.![]()
You could wish a Pointer-Type .p to define, that you want to return
a pointer, not only a value. But for me, it would also be to OOP-like![]()

MFG PMV
Re: Support pointer (structure) as return value in procedure
I longer discuss is not really useful.
Thanks for the fish.
Thanks for the fish.

Belive! C++ version of Puzzle of Mystralia
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
Re: Support pointer (structure) as return value in procedure
I understand it. I just dont agree with you.IceSoft wrote:It is a check during compile time...not runtime.
this check have only to do if there a structurepointer expected.
The i is a void pointer and need no check.
Open your mind and you understand it.
Actualy some of my sources would generate a warning with your check, even if there is nothing wrong.
Here is an example:
Code: Select all
Structure Pixel
Blue.a
Green.a
Red.a
Alpha.a
EndStructure
Procedure.i GetPixel()
Protected *Pixel.Pixel
*Pixel = AllocateMemory(SizeOf(Pixel))
*Pixel\Blue = 50
*Pixel\Green = 60
*Pixel\Red = 50
*Pixel\Alpha = 255
ProcedureReturn *Pixel
EndProcedure
Define *Pixel.Long
*Pixel = GetPixel()
I get why you want that, but i disagree on the importance of that feature. It's only usefull to detect if you used a wrong structure name. Actualy that never happend to me, not one time.
Re: Support pointer (structure) as return value in procedure
Maybe the check is part of option explicit. So no warning will raising with your code.Thorium wrote:Code: Select all
Structure Pixel Blue.a Green.a Red.a Alpha.a EndStructure Procedure.i GetPixel() Protected *Pixel.Pixel *Pixel = AllocateMemory(SizeOf(Pixel)) *Pixel\Blue = 50 *Pixel\Green = 60 *Pixel\Red = 50 *Pixel\Alpha = 255 ProcedureReturn *Pixel EndProcedure Define *Pixel.Long *Pixel = GetPixel()
But I belive your code is realy a good example why a check is usefull

Belive! C++ version of Puzzle of Mystralia
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
Re: Support pointer (structure) as return value in procedure
You doesn't understand the code?
Your wish would brake this fully functional code.
You know, that a 32-Bit color is only this number of 4 unsigned Bytes.
You can pass this value to every command, that needs a color.
MFG PMV

Your wish would brake this fully functional code.
You know, that a 32-Bit color is only this number of 4 unsigned Bytes.
You can pass this value to every command, that needs a color.
Code: Select all
Structure Pixel
Blue.a
Green.a
Red.a
Alpha.a
EndStructure
Procedure.i GetPixel()
Protected *Pixel.Pixel
*Pixel = AllocateMemory(SizeOf(Pixel))
*Pixel\Blue = $F0
*Pixel\Green = $3A
*Pixel\Red = $40
*Pixel\Alpha = $FF
ProcedureReturn *Pixel
EndProcedure
Define *Pixel.Long
*Pixel = GetPixel()
Debug Bin(*Pixel\l, #PB_Long)
Debug Bin($FF403AF0, #PB_Long)
Re: Support pointer (structure) as return value in procedure
I understand your code. It is a bad one.
Better:
And you get intelisense from the editor too 
Please try it.
Better:
Code: Select all
Define *Pixel.Pixel

Please try it.
Belive! C++ version of Puzzle of Mystralia
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
Re: Support pointer (structure) as return value in procedure
Well the point is to not use the Pixel structure, because it can be easier to handle a pixel as a long in some situations and in some its easier to handle it as a structure of channels. Why is that bad? It's totaly legal and can improve readability.IceSoft wrote:I understand your code. It is a bad one.
Better:And you get intelisense from the editor tooCode: Select all
Define *Pixel.Pixel
Please try it.
Re: Support pointer (structure) as return value in procedure
If...
... is allowed, then it would make somehow sense to be able to do something like...
Code: Select all
a.struct = b.struct
Code: Select all
Procedure.struct test(x)
...
ProcedureReturn something.struct
EndProcedure
a.struct = test(x)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
Re: Support pointer (structure) as return value in procedure
Maybe you are right for 'byValues' returns.blueznl wrote:If...
... is allowed, then it would make somehow sense to be able to do something like...Code: Select all
a.struct = b.struct
Code: Select all
Procedure.struct test(x) ... ProcedureReturn something.struct EndProcedure a.struct = test(x)
But not for pointers. Look this is working:
Code: Select all
*a.aStr = *b.aStr
Syntax error is on the definition of the procedure here:
Code: Select all
declare.*aStr test(x)
*a.aStr = test(x)
Yes I know I can make it like this:
Code: Select all
declare.i test(x)
Belive! C++ version of Puzzle of Mystralia
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
Re: Support pointer (structure) as return value in procedure
Yeah, it would not work well for a pointer, I know. But for a structure it should work well, don't you think so?
As for a pointer, a pointer is just that: a pointer.
So, if you return a pointer, you return a numeric value, which actually points to something in memory. The returned value does not have a type (beyound being a pointer, that is).
What's stored at the memory location the pointer points to can't be told in the procedure declaration or its return value.
Hmmm.
Which means, that returning a pointer works fine as it is
I only want to add returning a structure, and I guess that should be within the logical limitations of the language... let pointers live and be free, I'd say 
As for a pointer, a pointer is just that: a pointer.
So, if you return a pointer, you return a numeric value, which actually points to something in memory. The returned value does not have a type (beyound being a pointer, that is).
What's stored at the memory location the pointer points to can't be told in the procedure declaration or its return value.
Hmmm.
Which means, that returning a pointer works fine as it is


( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
Re: Support pointer (structure) as return value in procedure
What I mean is: PureBasic supports only void* pointers on declaration.
Later you can use (cast) each void* (=.i) pointer.
My wish is: Support also "pointer to a structure" during declaration.
Later you can use (cast) each void* (=.i) pointer.
My wish is: Support also "pointer to a structure" during declaration.
Belive! C++ version of Puzzle of Mystralia
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
Re: Support pointer (structure) as return value in procedure
One day I will understand the things you're saying, until then... euh... I'll just keep on hoping 

( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
Re: Support pointer (structure) as return value in procedure
Ok here an actual example of my Chipmunk wrapper:blueznl wrote:One day I will understand the things you're saying, until then... euh... I'll just keep on hoping
Code: Select all
cpArbiterAlloc.i() As ...
cpArbiterInit.i(*par1.cpArbiter, *par2.cpShape, *par3.cpShape) As ...
cpArbiterNew.i(*par1.cpShape, *par2.cpShape) As ...
If PureBasic supports also return values of "pointer to a structure" I can make the reading of the wrapper better:
Code: Select all
cpArbiterAlloc.cpArbiter() As ...
cpArbiterInit.cpArbiter(*par1.cpArbiter, *par2.cpShape, *par3.cpShape) As ...
cpArbiterNew.cpArbiter(*par1.cpShape, *par2.cpShape) As ...
Hope you understand something about what I mean better now.
Belive! C++ version of Puzzle of Mystralia
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
Re: Support pointer (structure) as return value in procedure
@Fred/@freak,
Any change to add this feature to the PureBasic?
At least It will improve all wrapper and of course something more.
Any change to add this feature to the PureBasic?
At least It will improve all wrapper and of course something more.
Belive! C++ version of Puzzle of Mystralia
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...