Roberto Ierusalimschy wrote: [...] > At least in C, the standard defines that the type of a string literal is > "char*" (not const). But it also states that any attempt to modify the > contents of a string literal has undefined behavior... That's correct for C (well, actually it's an array of char), but not for C++, where it's an array of const char, *except* in this one particular circumstance. The relevant bits are 2.3.14.1: http://www.zib.de/benger/C++/clause2.html#s2.13.4 ...which describes string literals in general, and 4.2.2: http://www.zib.de/benger/C++/clause4.html#s4.2 ...where it describes the implicit casting behaviour. It's strictly for compatibility with C, and is labeled DEPRECATED in large letters. Nevertheless, I don't imagine it's going away any time soon... -- ┌── dg@cowlark.com ─── http://www.cowlark.com ─────────────────── │ "Parents let children ride bicycles on the street. But parents do not │ allow children to hear vulgar words. Therefore we can deduce that cursing │ is more dangerous than being hit by a car." --- Scott Adams
Attachment:
signature.asc
Description: OpenPGP digital signature