Page 1 of 1
[5.10B1] Procedure.i is no longer useful
Posted: Fri Dec 21, 2012 3:29 pm
by IceSoft
I miss a new syntax check for returning a pointer of a structure from a function
This example is working but I use procedure.i (works also without adding the .i on the procedure key word)
Code: Select all
Structure myStructure
a.i
b.d
c.s
EndStructure
Procedure.i test(*aa.myStructure)
Debug "Procedure.i test(*aa.myStructure)"
Debug *aa\a
ProcedureReturn *aa
EndProcedure
a.myStructure
a\a = 11
a\b = 44
a\c = "Test"
*b.myStructure = @a
Debug *b\a
Debug *b\b
Debug *b\c
*c.myStructure = test(*b)
Debug *c\a
Debug *c\b
Debug *c\c
Here an example for a structure pointer return value Syntax (Only an idea):
Procedure.<structure>* Functionname(Parameters)
Code: Select all
Procedure.myStructure* test1(*aa.myStructure)
Debug "Procedure.myStructure test1(*aa.myStructure)"
Debug *aa\a
ProcedureReturn *aa
EndProcedure
Re: [5.10B1] Procedure.i is no longer useful
Posted: Fri Dec 21, 2012 4:06 pm
by freak
Is this a feature request? Where is the bug?
Re: [5.10B1] Procedure.i is no longer useful
Posted: Fri Dec 21, 2012 4:24 pm
by IceSoft
freak wrote:Is this a feature request? Where is the bug?
Bug or request? Make your own decission. It is not important how you declare this incomplete behavior of a purebasic syntax check;-)
I can returning a pointer of a structure. But I cannot declare the structure pointer as return value. That is it was I miss (not wish).
Re: [5.10B1] Procedure.i is no longer useful
Posted: Fri Dec 21, 2012 4:47 pm
by Shield
IceSoft wrote:I can returning a pointer of a structure. But I cannot declare the structure pointer as return value. That is it was I miss.
That is simply because PB doesn't support this (unfortunately). The fact that you can return a structure pointer from an Integer procedure is because
PB does an implicit cast (unfortunately

), and it does that everywhere.
So no bug.
Re: [5.10B1] Procedure.i is no longer useful
Posted: Fri Dec 21, 2012 5:04 pm
by IceSoft
Shield wrote:IceSoft wrote:I can returning a pointer of a structure. But I cannot declare the structure pointer as return value. That is it was I miss.
That is simply because PB doesn't support this (unfortunately). The fact that you can return a structure pointer from an Integer procedure is because
PB does an implicit cast (unfortunately

), and it does that everywhere.
So no bug.
ok.
Please explain me this:
I get a syntax check error with 5.10 when I write:
correct is
Thats is ok but why get I no syntax error using
but with this one i got an Syntax check error
Code: Select all
Procedure.Integer test()
a.i
ProcedureReturn a
EndProcedure
and last but not least explain me the return value behavior of this but functions:
Code: Select all
Procedure testvalue()
a.integer
ProcedureReturn a
EndProcedure
Procedure.i testpointer()
*a.integer
ProcedureReturn *a
EndProcedure
Debug testvalue()
Debug testpointer()
Re: [5.10B1] Procedure.i is no longer useful
Posted: Fri Dec 21, 2012 5:53 pm
by Demivec
IceSoft wrote:and last but not least explain me the return value behavior of this but functions:
Code: Select all
Procedure testvalue()
a.integer
ProcedureReturn a
EndProcedure
Procedure.i testpointer()
*a.integer
ProcedureReturn *a
EndProcedure
Debug testvalue()
Debug testpointer()
I'll comment the above code to explain the values:
Code: Select all
Procedure testvalue()
a.integer
;When the structure is used without a field it returns the address of the structure.
;To return the value of a structure field use the field (i.e. a\i)
ProcedureReturn a
EndProcedure
Procedure.i testpointer()
*a.integer
ProcedureReturn *a ;returns the value of the pointer, which is zero since it has not been assigned any other value since being declared
EndProcedure
Debug testvalue()
Debug testpointer()
Re: [5.10B1] Procedure.i is no longer useful
Posted: Fri Dec 21, 2012 6:34 pm
by Shield
IceSoft wrote:
Please explain me this:
I get a syntax check error with 5.10 when I write:
correct is
Thats is ok...
Right, because typed pointers don't make sense, it only makes sense if the type refers to the target memory.
IceSoft wrote:
but with this one i got an Syntax check error
Code: Select all
Procedure.Integer test()
a.i
ProcedureReturn a
EndProcedure
Yes, because Integer is not the same as ".i". Integer is a structured type, not a plain data type.
IceSoft wrote:
and last but not least explain me the return value behavior of this but functions:
Code: Select all
Procedure testvalue()
a.integer
ProcedureReturn a
EndProcedure
Procedure.i testpointer()
*a.integer
ProcedureReturn *a
EndProcedure
Debug testvalue()
Debug testpointer()
The first procedure returns the address of the structured variable 'a'. Because that variable is placed on the stack,
it will be dropped after returning from the procedure, i.e. the pointer is useless because the variable doesn't exist anymore.
If you write ProcedureReturn a\i you will get the actual "plain data" value.
The second procedure returns a pointer to an Integer structure.
If you use allocate memory inside the procedure you can create a memory block which is still valid after
returning from the procedure. Since PB uses implicit type casting, it will cast the address to an integer
which is technically the same (since both are regular integer values of the same size).
I said it's no bug...that doesn't mean I don't agree on sometimes inconsistent syntax and missing features
which are essential in
my opinion.