Page 1 of 1
Wishlist for Structure like in C?
Posted: Fri Jun 14, 2024 4:45 pm
by threedslider
Can we have Structures in PB like C programming for example :
Code: Select all
Structure Type
x.f
y.f
z.f
EndStructure
Procedure.Type init(_x.f, _y.f, _z.f)
var.Type
var\x = _x
var\y = _y
var\z = _z
ProcedureReturn var
EndProcedure
other_var.Type
other_var = init(0.0, 0.0, 0.0)
it is a wishlist for everyone and can make more easier in programming !
Please adding this feature !

Re: Wishlist for Structure like in C?
Posted: Fri Jun 14, 2024 7:32 pm
by DarkDragon
There are structures like in C already?! Or do you mean structured return values? You can return a pointer.
Re: Wishlist for Structure like in C?
Posted: Fri Jun 14, 2024 9:46 pm
by threedslider
@DarkDragon : I need the function stuff for structure and return type as complex expression like to C but in PB

Re: Wishlist for Structure like in C?
Posted: Sat Jun 15, 2024 10:20 am
by DarkDragon
threedslider wrote: Fri Jun 14, 2024 9:46 pm
@DarkDragon : I need the function stuff for structure and return type as complex expression like to C but in PB
Code: Select all
Structure Type
x.f
y.f
z.f
EndStructure
Procedure.i init(_x.f, _y.f, _z.f)
Protected *var.Type
*var = AllocateStructure(Type)
*var\x = _x
*var\y = _y
*var\z = _z
ProcedureReturn *var
EndProcedure
Define *other_var.Type
*other_var = init(0.0, 1.0, 2.0)
If *other_var <> #Null
Debug *other_var\x
Debug *other_var\y
Debug *other_var\z
FreeStructure(*other_var)
EndIf
Re: Wishlist for Structure like in C?
Posted: Sat Jun 15, 2024 12:37 pm
by threedslider
Wow ! It is so flexible this PB !!
Thanks for your tips @DarkDragon !
Re: Wishlist for Structure like in C?
Posted: Sat Jun 15, 2024 1:45 pm
by mk-soft
Fast mode ...
Code: Select all
Structure sData
x.f
y.f
z.f
EndStructure
DataSection
mydefaultdata:
Data.f 0.0, 1.0, 2.0
EndDataSection
Global myData.sData
CopyMemory(?mydefaultdata, @myData, SizeOf(myData))
Debug myData\x
Debug myData\y
Debug myData\z
Re: Wishlist for Structure like in C?
Posted: Sat Jun 15, 2024 3:08 pm
by threedslider
Nice @mk-soft !
Any is there to use a type of structure only without using the cost of memory ? For example returning only structure type without pointer ?
Thanks.
Re: Wishlist for Structure like in C?
Posted: Sat Jun 15, 2024 4:34 pm
by mk-soft
The struture type is only available at compile time.
There is no structure information at runtime. This means that no memory is used for it.
Re: Wishlist for Structure like in C?
Posted: Mon Oct 14, 2024 12:39 pm
by sst
Another solution:
Code: Select all
EnableExplicit
Structure Type
x.f
y.f
z.f
EndStructure
Procedure init(_x.f,_y.f,_z.f, *a.Type)
*a\x=_x.f
*a\y=_y.f
*a\z=_z.f
EndProcedure
Define other_var.Type
init(1,2,3,@other_var)
Debug other_var\x ;1.0
Debug other_var\y ;2.0
Debug other_var\z ;3.0
Re: Wishlist for Structure like in C?
Posted: Wed Oct 16, 2024 8:34 am
by threedslider
@sst : Wow ! You are new and given the solution is great
Thank you a lot
