Some of my suggestions return to custom types

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
callroot
User
User
Posts: 64
Joined: Sat Mar 05, 2016 10:46 pm

Some of my suggestions return to custom types

Post by callroot »

Code: Select all

Structure myBigStructure
  a.b
  b.s
  c.s
  d.i
  e.l
  f.q
EndStructure

Procedure.*myBigStructure foo()

  ProcedureReturn *a
  
EndProcedure 
Julian
Enthusiast
Enthusiast
Posts: 276
Joined: Tue May 24, 2011 1:36 pm

Re: Some of my suggestions return to custom types

Post by Julian »

You can do it this way, otherwise the scope of myBigStructure would last past the procedure its created in.

Code: Select all

Structure myBigStructure
  a.b
  b.s
  c.s
  d.i
  e.l
  f.q
EndStructure

Procedure foo(*test.myBigStructure)
  
  *test\a = 1
  
EndProcedure

Define moo.myBigstructure

foo(@moo)
Debug moo\a
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Some of my suggestions return to custom types

Post by Demivec »

You can do it this way also:

Code: Select all

Structure myBigStructure
  a.b
  b.s
  c.s
  d.i
  e.l
  f.q
EndStructure

Procedure.i foo() ;*myBigStructure
  Protected *a.myBigStructure
  
  ;structure is created here, it has to be freed by caller
  *a = AllocateStructure(myBigStructure)
  *a\a = 5
  
  ProcedureReturn *a
EndProcedure

Define *b.myBigStructure

*b = foo()
Debug *b\a

FreeStructure(*b)
Post Reply