Structures as return values for procedures

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Structures as return values for procedures

Post by blueznl »

Code below says it all...

Code: Select all

Structure xx
  a.i
  b.i
EndStructure
;
Procedure.xx pfew()
  Protected q.xx
  q\a = 1
  q\b = 2
  ProcedureReturn q
EndProcedure

Global z.xx
z = pfew()
Debug z\a
Debug z\b
( 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... )
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Structures as return values for procedures

Post by STARGÅTE »

PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Structures as return values for procedures

Post by blueznl »

Well, in that case see it as a reminder :-) Using pointers is soooooo 1970's...
( 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... )
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Structures as return values for procedures

Post by ts-soft »

blueznl wrote:Using pointers is soooooo 1970's...
Basic in the 70's doesn't support pointers. Pointer comes later in modern Basic's :mrgreen:
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Structures as return values for procedures

Post by STARGÅTE »

@blueznl: That's your opinion!

A procedure to pass a pointer, in which it can write directly inside, is faster than if the entire structure (with Longs, Strings, Lists, etc.) are copied to each return from the procedure in the variable, like CopyStructure().

EDIT:
But I agree with you!
It would make some things "simpler".
and it's not forced to use it.
Thus, you can always use pointers if you need more speed.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
Post Reply