Re: Results of the memswap() smackdown from the thread "Sorting" assignment



In article <47B5C712.55AE336F@xxxxxxxxx>, CBFalconer
<cbfalconer@xxxxxxxxx> writes
If we define a "string literal" as "characters between
non-escaped quotes" then C strings can contain nuls, as I showed.

We don't. From N869:
[...]

Actually, a "string literal" *is* "characters between non-escaped
quotes":

6.4.5 String literals
Syntax
string-literal:
" s-char-sequenceopt "
L" s-char-sequenceopt "
s-char-sequence:
s-char
s-char-sequence s-char
s-char:
any member of the source character set except the double-
quote ", backslash \, or new-line character
escape-sequence

Description
A character string literal is a sequence of zero or more multibyte
characters enclosed in double-quotes, as in "xyz". A wide string
literal is the same, except prefixed by the letter L.

As such, it can only contain a NUL if that is a valid character in the
extended source character set. Very probably it isn't.

The string literal "ab\0cd" causes the creation of an array of 6 chars
initialized with { 'a', 'b', 0, 'c', 'd', 0 }, but that isn't the string
literal, it's an array.

"string literal" is a compile-time concept. "string" is a run-time one.

--
Clive D.W. Feather | Home: <clive@xxxxxxxxxx>
Tel: +44 20 8495 6138 (work) | Web: <http://www.davros.org>
Fax: +44 870 051 9937 | Work: <clive@xxxxxxxxx>
Please reply to the Reply-To address, which is: <clive@xxxxxxxxxx>
.



Relevant Pages

  • Re: could you help me about this problem?
    ... struct student *create{ ... Here you create a string literal of one character length, ... This may be placed in memory marked as ... String literals are not modifiable. ...
    (comp.lang.c)
  • Re: Question related to string functions
    ... array whose size is specified as exactly the length of the array, ... "A character string literal has static storage duration and type "array ... not a special case of string literals. ... unknown size) initialize the elements of the array. ...
    (comp.lang.c)
  • RE: Double quotes in select statement throw an error
    ... quotes for all string literals and that these other drivers/servers handled ... non-standard syntax and it works. ... Use a valid query: ...
    (perl.dbi.users)
  • Re: The linf project
    ... Whatever the native character set on ... should be permitted in string literals. ... No non-printable character ... no deficiencies and the other way is to make it so complicated ...
    (comp.lang.fortran)
  • Re: Can Javascript work with Multiple lines of Text.
    ... above HTML code using Javascript. ... string literals are forbidden from including line terminators in there ... the line feed character may be ... all escape sequences start with the backslash character) (the last two ...
    (comp.lang.javascript)