Topic: difference in trigraphs between C++ and C
Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1999/02/11 Raw View
AllanW@my-dejanews.com writes:
>In article <36C06907.6E09C996@technologist.com>,
> David R Tribble <dtribble@technologist.com> wrote:
>> Steve Clamage wrote:
>> > CD2 contained errors in the description of trigraphs that were
>> > corrected in the final standard.
>> In particular, and in response to Daniel's post, '???' is not a
>> trigraph (it was implied that it was in the earlier draft examples
>> quoted by Daniel).
>>
>> Thus, correcting the example:
>> [Example: The sequence "???=" becomes "?#".
>> The sequence "?????????" remains "?????????".]
>I hadn't noticed that change. Now that there is no trigraph
>equivalent to a question mark, how do I make a string constant
>with three question marks, an equals sign, and a nul?
You can use an escaped question mark in the sequence. The
sequence \? in a character or string literal is equivalent
to just ?. Trigraphs are converted during translation phase 1,
but escape sequences not until phase 3. Therefore, you
escape the question mark just before the special character:
to get write
??= ?\?=
??/ ?\?/
??' ?\?'
??( ?\?(
??) ?\?)
??! ?\?!
??< ?\?<
??> ?\?>
??- ?\?-
??x ??x -- no escape needed for any other character
During phase 1, no trigraph is seen, and no question mark is
altered. During phase 3, the "\?" sequence is converted to "?".
Of course, if you lack the backslash character, you need to
write a trigraph for it. To get ??=, for example, you write
"???/?=". During phase 1, that gets converted to "?\?=", and
during phase three it gets converted to "??=".
--
Steve Clamage, stephen.clamage@sun.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: AllanW@my-dejanews.com
Date: 1999/02/11 Raw View
In article <36C06907.6E09C996@technologist.com>,
David R Tribble <dtribble@technologist.com> wrote:
> Steve Clamage wrote:
> > CD2 contained errors in the description of trigraphs that were
> > corrected in the final standard.
> In particular, and in response to Daniel's post, '???' is not a
> trigraph (it was implied that it was in the earlier draft examples
> quoted by Daniel).
>
> Thus, correcting the example:
> [Example: The sequence "???=" becomes "?#".
> The sequence "?????????" remains "?????????".]
I hadn't noticed that change. Now that there is no trigraph
equivalent to a question mark, how do I make a string constant
with three question marks, an equals sign, and a nul?
I am aware that I could break it up, as in
"??" "?="
but can it be done with one token? Is
"???\="
legal?
... If that last one is legal, then what happens to
"???/?="
I'm thinking this is equivalent to
"?\?="
which is also equivalent to
"??="
which, finally, is equivalent to
"#"
Is that right?
----
AllanW@my-dejanews.com is a "Spam Magnet" -- never read.
Please reply in USENET only, sorry.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: David R Tribble <dtribble@technologist.com>
Date: 1999/02/10 Raw View
Steve Clamage wrote:
>
> Daniel Villeneuve <danielv@crt.umontreal.ca> writes:
>> In CD2, I found the following example on trigraphs that seems
>> contradicting, and that conflicts with the way C89 and C9X define
>> unused
>> question marks (?) in the trigraph replacement phase (phase 1).
>
> CD2 contained errors in the description of trigraphs that were
> corrected in the final standard.
>
> CD2 is not a good reference for details. Many details in CD2
> are wrong. In fact, that's one reason why a Committee Draft
> gets sent out for comment -- so that more people will look
> at the draft and find errors.
>
> Refer to the FAQ mentioned below for more on this subject.
In particular, and in response to Daniel's post, '???' is not a
trigraph (it was implied that it was in the earlier draft examples
quoted by Daniel).
Thus, correcting the example:
[Example: The sequence "???=" becomes "?#".
The sequence "?????????" remains "?????????".]
-- David R. Tribble, dtribble@technologist.com --
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Daniel Villeneuve <danielv@crt.umontreal.ca>
Date: 1999/02/02 Raw View
In CD2, I found the following example on trigraphs that seems
contradicting, and that conflicts with the way C89 and C9X define unused
question marks (?) in the trigraph replacement phase (phase 1).
<CD2>
[Note: no other trigraph sequence exists. Each ? that does not begin one
of the trigraphs listed above is not changed. ]
Trigraph replacement is done left to right, so that when two sequences
which could represent trigraphs overlap, only the first sequence is
replaced. Characters that result from trigraph replacement are never
part of a subsequent trigraph.
[Example: The sequence "???=" becomes "?=", not "?#". The sequence
"?????????" becomes "???", not "?". end example]
</CD2>
This contradicts the text in C9X (n2794.pdf), which I think is the same
as the one in C89:
<C9X>
No other trigraph sequences exist. Each ? that does not begin one of the
trigraphs listed above is not changed.
EXAMPLE The following source line
printf("Eh???/n");
becomes (after replacement of the trigraph sequence ??/)
printf("Eh?\n");
</C9X>
Interpreting the C9X example with the C++ semantics, we would obtain
printf("Eh?/n")
The C++ Standard seems to consider ??? as a trigraph for ?,
contradicting the fact that no other trigraphs exist but the 9 described
in the table.
Is there really a difference in the detection and management of
trigraphs between C++ and C?
--
Daniel Villeneuve
Graduate student in Operations Research
GERAD/Math matiques Appliqu es
cole Polytechnique de Montr al
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: stephen.clamage@sun.com (Steve Clamage)
Date: 1999/02/02 Raw View
Daniel Villeneuve <danielv@crt.umontreal.ca> writes:
>In CD2, I found the following example on trigraphs that seems
>contradicting, and that conflicts with the way C89 and C9X define unused
>question marks (?) in the trigraph replacement phase (phase 1).
CD2 contained errors in the description of trigraphs that were
corrected in the final standard.
CD2 is not a good reference for details. Many details in CD2
are wrong. In fact, that's one reason why a Committee Draft
gets sent out for comment -- so that more people will look
at the draft and find errors.
Refer to the FAQ mentioned below for more on this subject.
--
Steve Clamage, stephen.clamage@sun.com
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]