stringizing
Norman Diamond
diamond at jit533.swstokyo.dec.com
Fri Apr 26 14:50:57 AEST 1991
In article <9565 at cognos.UUCP> jimp at cognos.UUCP (Jim Patterson) writes:
>In article <1991Apr23.075527.19443 at tkou02.enet.dec.com> diamond at jit345.enet@tkou02.enet.dec.com (Norman Diamond) writes:
>>In article <14888 at darkstar.ucsc.edu> daniel at terra.ucsc.edu (Daniel Edelson) writes:
>>> #define str(x) #x
>>> printf("%s\n", str( hello\t\n\vworld\n\n));
>>>Is the output from this program supposed to be:
>>> hello world
>> Whether each nonempty sequence of white-space characters other than newline
>> is retained or replaced by one space character is implementation-defined.
>> hello\t\n\vworld\n\n\n
>>or
>> hello \n world\n\n\n
>You seem to be assuming that \t \v etc are whitespace characters. They
>aren't; they are escape sequences.
I guess you're right. When reading Mr. Edelson's question, I read the
\t and \v and \n as the actual characters instead of the escape sequences.
For some reason, I didn't make this mistake on the \n in the format string.
However, this was not my only mistake.
>The point at which escape characters are converted to characters is
>clearly defined by the standard section 2.1.1.2 Translation Phases.
>During step 4 ... the str(...) macro should be expanded. \t and \v should
>still be escape sequences at this point because in step 5
Yes.
>Note that \t \v etc are NOT translated except in character and string
>constants. Their appearance in other contexts is not valid (though I
>think the above example is valid).
Yes.
>My interpretation is that the entire string within the str() with
>the exception of the leading white space is string-ized. That is,
>the result of str( hello\t\n\vworld\n\n) is "hello\t\n\vworld\n\n".
>
>(Section 3.8.3.2 explains the string-ize function and it clearly
>states that leading and trailing whitespace is deleted while internal
>whitespace sequences are replaced by single spaces).
Sorry, I hadn't read that section of the manual for a while.
(In OO terminology, my mouth now "has-a" foot, though not "is-a" foot. :-)
--
Norman Diamond diamond at tkov50.enet.dec.com
If this were the company's opinion, I wouldn't be allowed to post it.
More information about the Comp.std.c
mailing list