Re: Malcolm's new book - Chapter 1 review



On 2007-08-11 05:30, Malcolm McLean <regniztar@xxxxxxxxxxxxxx> wrote:
"Eric Sosman" <Eric.Sosman@xxxxxxx> wrote in message
news:1186694915.312161@xxxxxxxxxxx
Good! At a stroke, you've cured three of the bugs
I spotted in your first chapter -- not by fixing them,
but by blaming them on the Standard. Bravo! Your book
gets better and better with each new finger-pointing!

The standard says that a char argument to isspace() is illegal. That's
clearly quite unacceptable.
I could have mentioned the issue, but it gives the impression that C is a
very difficult, almost unusable language. maybe legitimately, because the
committee is pushing it in that direction.
In fact it is so unlikely that the reader will use a system that does break
on char arguments,

Unlikely? On all compilers I've used except one the default char type
was signed (most had a switch to make it unsigned). On all systems I've
used since ca. 1990 the default character set included characters with
the high bit set. So on almost all systems I've used in the last 17
years the code

char *s;
...
while (*s) {
if (isspace(*s)) {
do_something();
}
}

would fail. It had to be

char *s;
...
while (*s) {
if (isspace((unsigned char)*s)) {
do_something();
}
}

Of course these days the assumption that 1 char is 1 character is often
wrong, so you'd have to use the wide- or multibyte-character
equivalents.

and because the standrad is so absurd, I thought it best
simply to sweep the matter under the carpet.

You are certainly entitled to your opinion that C is an absurd language.
So use a different language in your book. You can even use a language
which differs only a little from C. But if you do that, don't claim that
you are using "ANSI C", because you don't.

hp


--
_ | Peter J. Holzer | I know I'd be respectful of a pirate
|_|_) | Sysadmin WSR | with an emu on his shoulder.
| | | hjp@xxxxxx |
__/ | http://www.hjp.at/ | -- Sam in "Freefall"
.



Relevant Pages

  • Re: M2 for iPhone?
    ... You don't have to implement the entire standard - it specifically allows for conforming implementations to have limited compliance. ... The converse argument for COMPLEX is that unless you offer a language with a built-in complex data type, you stand no chance of winning over the FORTRAN users. ... It is not true that the ISO standard doesn't support multi-byte characters - it is carefully written to avoid specifying any particular character coding ...
    (comp.lang.modula2)
  • Re: Scripts & Communications
    ... These two machines had different character ... Machines had words, bits, and bytes. ... standard, ASCII, had a mapping of glyphs to ... Now the ISO standard has a mapping of 8 bits for every language ...
    (sci.crypt)
  • Re: Are _T() and TEXT() macros equivalent?
    ... by every single application developed in that language for the last 30 ... are not concerned if a char takes 1 byte or 100. ... Go through the standard and list the sections that use char as byte. ... void write ...
    (microsoft.public.vc.mfc)
  • Re: the standard is so strange
    ... char * p1 = xx; ... had fully defined the language. ... there were already different compilers ... You don't necessarily have to read the standard, ...
    (comp.lang.c)
  • Re: Are _T() and TEXT() macros equivalent?
    ... by every single application developed in that language for the last 30 ... Go through the standard and list the sections that use char as byte. ... Another example concerns any function that takes a void* and writes data as ...
    (microsoft.public.vc.mfc)