QB64 Phoenix Edition
Questions about _MEMs and UDT's - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: Chatting and Socializing (https://qb64phoenix.com/forum/forumdisplay.php?fid=11)
+--- Forum: General Discussion (https://qb64phoenix.com/forum/forumdisplay.php?fid=2)
+--- Thread: Questions about _MEMs and UDT's (/showthread.php?tid=799)



Questions about _MEMs and UDT's - justsomeguy - 08-22-2022

Is it possible to pass _MEM handles to Functions/Subs without having to make it global?

Is there a way to normalize the behavior of strings in UDT's? Uninitialized strings in UDT's are filled with CHR$(0), and initialized strings are padded with spaces at the end. Trying to determine the actual string length is difficult, because I can't tell if the spaces are intentional or not.

Are variable length strings in UDT allowed? I though that they weren't. But it seems if you use the right syntax they are allowed, but I found that I can get some strange behaviors if I use them. (Not demonstrated in code.)

I've demonstrated my questions in the following code.

Code: (Select All)
TYPE tTEST
  st AS STRING * 12
END TYPE

TYPE tTESTBUG
  AS STRING st
END TYPE

DIM AS tTEST test
DIM AS tTESTBUG testbug

PRINT "Uninitialized String."
prntSTR test

PRINT "Initialized String."
test.st = "Hello"
prntSTR test

PRINT "Variable length String in UDT? "
PRINT "Uninitiated String."
prntSTRBug testbug

PRINT "Initialized String."
testbug.st = "Hello"
prntSTRBug testbug


SUB prntSTR (test AS tTEST)
  DIM i AS LONG
  FOR i = 1 TO LEN(test.st)
    PRINT ASC(MID$(test.st, i, 1)); " ";
  NEXT
  PRINT
END SUB

SUB prntSTRBug (test AS tTESTBUG)
  DIM i AS LONG
  FOR i = 1 TO LEN(test.st)
    PRINT ASC(MID$(test.st, i, 1)); " ";
  NEXT
  PRINT
END SUB



RE: Questions about _MEMs and UDT's - SMcNeill - 08-22-2022

SUB foo (m AS _MEM) <-- can pass mem handles like so.

Variable Length strings in UDT are only half supported. The old team was working on them, then quit, and they've been stuck in a half implemented state ever since.