LWN.net Logo

Null-Terminated Strings

Null-Terminated Strings

Posted Nov 20, 2010 1:03 UTC (Sat) by cmccabe (guest, #60281)
In reply to: Null-Terminated Strings by pr1268
Parent article: Ghosts of Unix past, part 3: Unfixable designs

> I like your code example, but it might only work in C (not C++).

Sorry, you are confused. It works in both C++ and C.

> 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

Nope.

Here the enum is promoted to an integer. C++, like C, promotes a lot of types to integers under the right situations.

> 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.

There is no std::string in this example. You are confused.


(Log in to post comments)

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