Re: || putchar(ch == '\177' ? '?' : ch | 0100) == EOF)





"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 (to
show how much the language has improved if nothing else).
Thanks for your generous response. I understood the above, but about
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.

--

.



Relevant Pages

  • REVIEW/ACRA: Superfreaks # 9-13
    ... So, I finally got around to reading last month's batch of SUPERFREAKS, ... hard on Martin for the transparency of some of his character analogues. ... Now, during this, we get a personal B-plot with goofy Edward courting ... And that's control. ...
    (rec.arts.comics.creative)
  • Re: wide screen text mode?
    ... Is there a reason it *must* be DOS text mode? ... attribute color control. ... With a script or a long novel, each character can be assigned a custom ... pasted 4 such screens together to get a screen that is 1212x800. ...
    (comp.os.msdos.programmer)
  • Re: several simple questions about text boxes
    ... > I'm not the brightest MS Access user, so I need a little help. ... The answer depends on WHEN you need to get the length of the string. ... attempt to move off the control HAS NOT occurred. ... > Let's say I want to pull out the third character of any word, ...
    (microsoft.public.access.forms)
  • Re: Turnbased CRPG?
    ... >>TB CRPGs rely on player intelligence instead of reaction speed (i.e. the ... When it comes to tactical combat the ... control a party, the only way to really control them intelligently is ... I'm making the decisions for another character. ...
    (comp.sys.ibm.pc.games.rpg)
  • Re: Direct access to the UART?
    ... of them which I can control and the other which is absolutely out of my ... You may set-up the UART for the needed speed using the 16550 driver ... new character in the rx FIFO or when a character has been received. ... (l'indirizzo di reply di questo messaggio non è ...
    (microsoft.public.windowsce.platbuilder)