Re: || putchar(ch == '\177' ? '?' : ch | 0100) == EOF)
- From: c gordon liddy <grumpy196884@xxxxxxxxxxx>
- Date: Fri, 28 Mar 2008 00:28:12 -0700 (PDT)
"Keith Thompson" <kst-u@xxxxxxx> wrote in message news:
87hcerqseb.fsf@xxxxxxxxxxxxxxxxxx
"c gordon liddy" <c@xxxxxxxxxxxxx> writes:
Yes, that code is archaic, but it's of some historical interest (toThanks for your generous response. I understood the above, but about
show how much the language has improved if nothing else).
right here is where I hit the peter principle:
It uses a common convention (at least it's common on Unix) for
displaying non-printable characters. Control characters in the range
0 to 31 are represented as a '^' followed by another character,
usually an uppercase letter; it's determined by adding 64 to the
value. (On old keyboards, the control key actually worked by clearing
a bit in the 7-bit or 8-bit value that was transmitted.) The DEL
character, 127, is represented as ^?; this is a special case.
Characters with the high bit set, in the range 128 to 255, are called
"meta" characters (some old keyboards had a "meta" key that set this
bit), and are represented as "M-" followed by the representation of
the corresponding 7-bit character. For example, character 129 would
be printed as M-^A.
putchar() returns EOF on failure.
All this (except the EOF part) is very specific to the ASCII character
set, something that's not specified by the C standard, but it should
give you enough information to understand what the code is doing (with
a bit of work).
Similarly, I'm out of my depth with what follows the double pipe in the
second if clause.
|| putchar(ch == '\177' ? '?' : ch | 0100) == EOF)
Wouldn't \177 be a tri-graph? A perfectly-acceptable explanation might be
that it's beyond the scope of my present endeavor and can be omitted.
No, it's not a trigraph; trigraphs are introduced by a double question
mark. It's a character constant that uses an escape sequence. '\177'
is the character whose integer value is 177 in octal, or 127 in
decimal; it's the ASCII DEL character. "ch | 0100" yields the value
of ch with a certain bit forced on; it's terse way of mapping
control-A (1) to 'A" and so forth. The conditional expression is used
to handle the fact that mapping DEL to "^?" is a special case.
I think I could study the above for a long time and not really get
it. It's interesting but not germane to something that can be done in
standard C. I have a double problem with the double pipe here. Not
only is that which is on the right hand side of it obfuscated C, I
don't get the control mechanism. To me, it looks like
if this then that or the other.
I would suspect that there's another K&R exercise that speaks to this
in the realm of my own OS.
--
.
- Follow-Ups:
- Re: || putchar(ch == '\177' ? '?' : ch | 0100) == EOF)
- From: Keith Thompson
- Re: || putchar(ch == '\177' ? '?' : ch | 0100) == EOF)
- References:
- || putchar(ch == '\177' ? '?' : ch | 0100) == EOF)
- From: c gordon liddy
- Re: || putchar(ch == '\177' ? '?' : ch | 0100) == EOF)
- From: Keith Thompson
- || putchar(ch == '\177' ? '?' : ch | 0100) == EOF)
- Prev by Date: Re: compiling multiple source files
- Next by Date: Re: Implementation-defined behaviour
- Previous by thread: Re: || putchar(ch == '\177' ? '?' : ch | 0100) == EOF)
- Next by thread: Re: || putchar(ch == '\177' ? '?' : ch | 0100) == EOF)
- Index(es):
Relevant Pages
|