Le 20/05/2012 18:43, tobi a écrit : > > So my question bounces to Benoît: It's said in the docs that the three string > functions used above > are optimised so that they don't duplicate strings. Does that mean or is it a > general fact that I > cannot rely on the STRING() macro to extract a NUL-terminated string from a > given GB_STRING > argument? At least there doesn't seem to be a NUL byte which causes the > component to print > everything that follows until the end of the original string... > Brief explanation and after lunch, it's done. > > Regards, > Tobi >
No problem, I never told you how it works, so you couldn't guess! Gambas strings are not C strings (i.e. null byte terminated), but a combination of a string pointer (char *) and a length. To get the string pointer from a string argument, you must use the STRING() macro, but you already knew. To get the length of a string argument, you must use the LENGTH() macro. Now, the problem is that sometimes you cannot deal with such strings, and need a C-string. Hopefully, the interpreter provides the GB.ToZeroString() API that takes the string argument (through the ARG() macro) and returns a temporary C-string that will be automatically freed later. So, either you have: BEGIN_METHOD(MyMethod, GB_STRING arg) my_function(STRING(arg), LENGTH(arg)); END_METHOD or (if you really need a C-string): BEGIN_METHOD(MyMethod, GB_STRING arg) my_function(GB.ToZeroString(ARG(arg))); END_METHOD Regards, -- Benoît Minisini ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user