Posted Nov 18, 2010 17:24 UTC (Thu) by pr1268
In reply to: Null-Terminated Strings
Parent article: Ghosts of Unix past, part 3: Unfixable designs
I like your code example, but it might only work in C (not C++).
Two cases in point:
- Using the enum value as an array index might give unpredictable results since C++ treats enumerations as a distinct type (instead of int as in C)1
- The C++ standard library string can have '\0' characters anywhere inside the string (which may also lead to unpredictable behavior at runtime)2. Of course, you're referring to a C-style string, so this may be a moot point.
1 Stroustrup, B. The C++ Programming Language, Special Edition, p. 77
2 Ibid, p. 583
to post comments)