User: Password:
Subscribe / Log in / New account

Null-Terminated Strings

Null-Terminated Strings

Posted Nov 19, 2010 10:58 UTC (Fri) by etienne (guest, #25256)
In reply to: Null-Terminated Strings by pr1268
Parent article: Ghosts of Unix past, part 3: Unfixable designs

The enum is only used like (to have empty substring default to english), so no problem with its C++ size:

const char *curlang(const char *mltstr)
const char *ptr = mltstr;
for (unsigned cptlang = 0; cptlang < current_language; cptlang++)
while (*ptr++) {}
return (*ptr)? ptr : mltstr;

Oviously none of the substrings can have embedded zero char.

A C++ line of code like:
cout << "The " << big? "big " : "small " << "dog is " << age << " year old.";
needs an efficient storage for small strings, even more when doing a multi language software.

(Log in to post comments)

Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds