[RFC] std::string(0);

Loren James Rittle rittle@latour.rsch.comm.mot.com
Tue Jun 15 07:41:00 GMT 2004


In article <1087279330.1403.0.camel@localhost.localdomain>,
Dhruv Matani<dhruvbird@gmx.net> writes:

>>> BTW, would "" be equivalent to '\0'?

"" is a pointer.  '\0' is a character.

>> No, but ""[0] is equivalent to '\0'...

"Most" pointers may be dereferenced with [] thus ""[0] is a
dereferenced pointer (which happens to be '\0' by language definition ;-).

> I'm sorry, but what is: ""[0]?

If it is still not clear, maybe this context will help:

int printable_nibble (int i) { return "0123456789abcdef"[i % 16]; }

You will actually find this idiom/hack in real, production C code...

Regards,
Loren



More information about the Libstdc++ mailing list