[5.10B1] Procedure.i is no longer useful

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
IceSoft
Addict
Addict
Posts: 1682
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

[5.10B1] Procedure.i is no longer useful

Post 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
Belive! C++ version of Puzzle of Mystralia
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: [5.10B1] Procedure.i is no longer useful

Post by freak »

Is this a feature request? Where is the bug?
quidquid Latine dictum sit altum videtur
User avatar
IceSoft
Addict
Addict
Posts: 1682
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: [5.10B1] Procedure.i is no longer useful

Post 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).
Belive! C++ version of Puzzle of Mystralia
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: [5.10B1] Procedure.i is no longer useful

Post 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 :P), and it does that everywhere.

So no bug.
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
User avatar
IceSoft
Addict
Addict
Posts: 1682
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: [5.10B1] Procedure.i is no longer useful

Post 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 :P), 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:

Code: Select all

*a.i
correct is

Code: Select all

*a.Integer
Thats is ok but why get I no syntax error using

Code: Select all

Procedure.i 
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()
Belive! C++ version of Puzzle of Mystralia
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
User avatar
Demivec
Addict
Addict
Posts: 4259
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: [5.10B1] Procedure.i is no longer useful

Post 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()
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: [5.10B1] Procedure.i is no longer useful

Post by Shield »

IceSoft wrote: Please explain me this:
I get a syntax check error with 5.10 when I write:

Code: Select all

*a.i
correct is

Code: Select all

*a.Integer
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:

Code: Select all

Procedure.i 
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.
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
Post Reply