01-12-2006, 04:19 AM
Sorry for the double-post.
For those interested: How strings get passed by value
So, it seems that null-spersed-strings passed by value get truncated "by design", since a pointer is passed instead of the descriptor - which means we no longer have explicit length information; length must be determined incrementally - thus the truncation.
Moral of the story: for strings that may possibly contain a null character, pass by reference (if you can't safely ignore truncation). For non-modifiable strings that are guaranteed not to have a null character, pass by value, otherwise pass by reference. (if you're passing a string by reference and you don't want it modified [text, key, for example], prefer to create a local copy [result] and only use that copy throughout the function.
update: the above behavior will be changing in an indefinent amount of time . strings passed by value will be deep-copied instead of having an address passed instead. happy happy, joy joy
For those interested: How strings get passed by value
So, it seems that null-spersed-strings passed by value get truncated "by design", since a pointer is passed instead of the descriptor - which means we no longer have explicit length information; length must be determined incrementally - thus the truncation.
Moral of the story: for strings that may possibly contain a null character, pass by reference (if you can't safely ignore truncation). For non-modifiable strings that are guaranteed not to have a null character, pass by value, otherwise pass by reference. (if you're passing a string by reference and you don't want it modified [text, key, for example], prefer to create a local copy [result] and only use that copy throughout the function.
update: the above behavior will be changing in an indefinent amount of time . strings passed by value will be deep-copied instead of having an address passed instead. happy happy, joy joy
stylin: