Page 1 of 1

[Implemented] fixed length strings (in structs)

Posted: Sun Oct 05, 2003 10:46 pm
by blueznl
(edited this to make it more clear and iron out some typo's / mistakes)

structure xyz
a.l
b.b[16]
endstructure

apple.xyz
apple\a = 1
pokes(@apple\b,"test")

how nice would it be to do:

structure xyz
a.l
b.c[16]
endstructure

apple.xyz
apple\a = 1
apple\b = "test"

mucho cleaner code...

in other words: how about a new type, fixed length strings (or memory blocks) that is not truncated when it contains a zero, behaves somewhat like a string, i'll use .c as postfix for now, but .m is another candidate :)

typical use: anywhere where you need memory blocks without going through the allocate memory cycle, and as a part of structs that actually contain fixed length strings or buffers

examples

a.c[5] = "" ; a fixed length string of 5 chars
b.c[2] = ""

a = "test" ; fill a.c with 4 characters and a zero
b = "test" ; only the first two chars fit

c.s = a + b ; convert a and b to strings (truncate if there are zero's) then add them

d.c[16384]="" ; quickly create a buffer with length 16 kb

so after the code above, a.c would contain "test[null]" and b.c would contain "te", c.s would contain "testte"

i think this makes sense, my explanation might not :D

here's a sample struct from another post, to see where it would come in handy:

typedef struct _RASDIALPARAMS {
DWORD dwSize;
TCHAR szEntryName[RAS_MaxEntryName + 1];
TCHAR szPhoneNumber[RAS_MaxPhoneNumber + 1];
TCHAR szCallbackNumber[RAS_MaxCallbackNumber + 1];
TCHAR szUserName[UNLEN + 1];
TCHAR szPassword[PWLEN + 1];
TCHAR szDomain[DNLEN + 1] ;
} RASDIALPARAMS;