Re: I watch Bones for the accuracy and attention to detail...



On 2010-04-22, David Gersic <usenet_spam_trap@xxxxxxxxxxxxxxxxxxxx> wrote:
Presumably the man makes at least some money by publishing books on
subjects that he does not understand. There are a great many subjects
that I do not understand. How do I get one of these publishing deals
like Schildt? I'd be happy to pump out books on quantum theory or
tennis or any other random subject that I don't have a clue about nor
any real desire to acquire one. Profit!

Shallow answer: Write readably and engagingly, whether or not you know
what you're talking about.

Deeper answer: Look more closely at the combination of:
1. Falsely claiming that because "EOF" is a valid integer, it
can occur in binary files.
2. Mistakenly using "char ch" to hold the results of getchar().

On a typical Windowsy system, "char" is signed, and EOF is -1. Thus,
"char" can hold EOF. Thus there exists a character which, stored in a char,
compares equal to EOF, but this character is rare in text files. Since
most people don't understand that text/binary are characteristics of C
streams, rather than of underlying files, they end up with the belief that
a "binary file" is distinct from a "text file", and try carefully to use
text mode for text files and binary mode for binary files.

So, what happens:

1. Their test programs work fine on most text files, because the character
which can be mistaken for EOF is rare.
2. A test program run on a binary file indeed produces false positives,
because they got the types wrong.
3. Schildt's proposed resolution to this problem does indeed correct
the problem.

But wait! *Other books do not mention this problem.* That means that,
the victim of Schildt's writing ends up not only with a self-consistent
set of beliefs about how to use getchar() and EOF, but also with the
belief that this is esoteric knowledge of a hidden pitfall of C, which
many other books have failed to cover.

So people end up thinking they've gotten a particularly good book which
covers details other books omit. Meanwhile, they never notice trivial
omissions like any reference, ever, to structure padding. (If there is
one, I couldn't find it -- I went over the likely sections pretty closely).
Why would they? They don't know about it, and 90% of the time, a structure
contains only objects which all have the same alignment requirements
and need no padding anyway.

Luckily, my personal hero has taken to flooding Usenet and other sources
with reminders that, so far as we can tell, every competent person who has
reviewed Schildt's books now agrees that they're awful. (I think a few
people were briefly taken in by the engaging writing, though.)

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam@xxxxxxxxx
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
.



Relevant Pages

  • Re: memory leak?
    ... The issue is that in the TMS30C90, with 80-bit character types, this ... Yes, it is well-defined in terms of what happens, but in fact if EOF is a constant which ... is out-of-band for all char/unsigned char values (which is how it is done, ... to create a conforming implementation on a word-addressed machine. ...
    (microsoft.public.vc.mfc)
  • Re: detab utility challenge.
    ... it is possible that some valid character may ... I assume wchar has similar rules to char. ... I'd guess the answer is the same, use feof() to verify an eof ... no. Undefined Behaviour is a technical term from the standard. ...
    (comp.lang.c)
  • Re: Value of EOF
    ... If char is signed, ... >>(the most common value of EOF) is well within its range. ... CBFalconer simply made a slight error. ... character set have to have positive values when expressed as plain ...
    (comp.lang.c)
  • Re: Puzzle!
    ... detect the character that terminated a numerical field. ... * Skip to non-blank on f, and return that char. ... static int ignoreblks ... which may be \n or EOF ...
    (comp.lang.c)
  • LCC 2006, Friday: a vaguely on topic travelogue at last
    ... anything that I claim anyone said on any panel is based on notes I ... VD is from Toronto, FW from London, LR British and West USian, RB is writing ... stick to facts - her books are like real life, ... Ottowan - writes about normal people who do murders - character over ...
    (rec.arts.mystery)