Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Declaring Functions AS TYPEs
#14
This UDT as function thing is kewl, but there is a simple reason why "internally" they are being passed around as pointers.

If one such variable of type UDT has to be passed by value, or become the return value of a function, it will have to be copied. But QB64 might already do this with strings because QuickBASIC did it. This could cause performance issues.

Purebasic doesn't allow UDT's passed by value. The parameter to subprograms for an UDT must be a pointer. It's because the compiler cannot asume what is the size of one type which is not a simple one like 64-bit integer. Otherwise it has to decide what will be a character, if it's Unicode or not.

The thing with _MEM works with any UDT. What sucks is that one has to use "m.OFFSET + x" notation to get to the fields and figure out the precise order of the types of the members, as listed in the source code. If all members are integer or floating point then it's easier, but real life in programming is never that easy. Another thing that sucks is that the UDT could never be the direct return value of a FUNCTION. It could only depend on the SUB side-effect to change it because "internally" only a pointer is being involved.
Reply


Messages In This Thread
Declaring Functions AS TYPEs - by TerryRitchie - 08-16-2023, 02:26 AM
RE: Declaring Functions AS TYPEs - by dbox - 08-16-2023, 02:56 AM
RE: Declaring Functions AS TYPEs - by mnrvovrfc - 08-16-2023, 03:08 AM
RE: Declaring Functions AS TYPEs - by OldMoses - 08-16-2023, 11:53 AM
RE: Declaring Functions AS TYPEs - by mnrvovrfc - 08-16-2023, 12:33 PM
RE: Declaring Functions AS TYPEs - by a740g - 08-16-2023, 12:38 PM
RE: Declaring Functions AS TYPEs - by bplus - 08-16-2023, 02:38 PM
RE: Declaring Functions AS TYPEs - by Kernelpanic - 08-16-2023, 04:14 PM
RE: Declaring Functions AS TYPEs - by grymmjack - 08-16-2023, 09:50 PM
RE: Declaring Functions AS TYPEs - by mnrvovrfc - 08-16-2023, 11:25 PM
RE: Declaring Functions AS TYPEs - by bplus - 08-17-2023, 12:41 AM



Users browsing this thread: 10 Guest(s)