Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > ANN: Long-overdue CU bug-fix

Reply
Thread Tools

ANN: Long-overdue CU bug-fix

 
 
Richard Heathfield
Guest
Posts: n/a
 
      09-06-2007
I got an email today from a CU reader who wanted to know what had
happened to Chapter 15's sparse.c and sparse.h - neither of which
appear on the CD. He was ever so polite about it, mind you - but I
still felt really guilty because of course this should never have
happened.

The sparse.c omission was easy to explain - that was the original name
of a file which was later split into many. But the sparse.h header was
in fact completely missing. The author of the relevant chapter did once
send me the header (about two or three years after publication!) but
this was at a time when my work schedule was more insane than usual and
I lost track of it completely, together with his email address, when a
disk crashed; a disk that should have been backed up and wasn't.

I have spent today reconstructing the header from information provided
in the text and from hints in the source files, and then getting the
test-driver to work. This involved a considerable amount of hacking,
during the course of which I must have removed something like 200
unnecessary casts! (They were in my way, making the code harder to
read, so they had to go. I think there probably are still plenty left,
though, in the code I /didn't/ touch...)

The revised code is now freely available on my Web site:

http://www.cpax.org.uk/prg/portable/...pter15Code.zip

It's about 20KB, and I have about 480kbps upload (in theory) - so if you
time it right, it shouldn't take more than about twenty minutes to
grab. (If you're astoundingly lucky, of course, it'll only take half a
second or so.)

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
 
Reply With Quote
 
 
 
 
jacob navia
Guest
Posts: n/a
 
      09-06-2007
Richard Heathfield wrote:

[snip]

Are the other bugs in C Unleashed fixed?

Specifically in Chapter 11, page 353 you assume
sizeof pointer is equal to sizeof int...

Here is the buggy code:
It will work when sizeof pointer is equal to sizeof int
(windows or linux 32 bit versions) but will crash when
sizeof int != sizeof pointer (windows 64 bits.

Exercise:

Where does Heathfield go wrong?

#include <stdio.h>
#include <stdlib.h>
typedef int T;
T **Allocate(size_t m,size_t n)
{
T **a;
T *p;
size_t Row;

a = malloc(m*n*sizeof **a + m * sizeof *a);
if (a) {
for (Row=0,p=(T *)a + m; Row < m; Row++,p+=n) {
a[Row]=p;
}
}
return a;
}

int main(void)
{
T **array;
int i;
int j;
int total=0;
int Row=4;
int col=7;

array = Allocate(Row,col);
if (array != NULL) {
for (i=0; i<Row;i++)
for (j=0; j<col; j++)
array[i][j] = i+j;
for (i=0; i<Row;i++)
for(j=0;j<col;j++)
total+=array[i][j];

printf("Total is %d\n",total);
free(array);
}
return 0;
}
 
Reply With Quote
 
 
 
 
Philip Potter
Guest
Posts: n/a
 
      09-06-2007
jacob navia wrote:
> Richard Heathfield wrote:
>
> [snip]
>
> Are the other bugs in C Unleashed fixed?
>
> Specifically in Chapter 11, page 353 you assume
> sizeof pointer is equal to sizeof int...
>
> Here is the buggy code:
> It will work when sizeof pointer is equal to sizeof int
> (windows or linux 32 bit versions) but will crash when
> sizeof int != sizeof pointer (windows 64 bits.
>
> Exercise:
>
> Where does Heathfield go wrong?


One of your most-used arguments against your critics is that their arguments are
not backed up by substance. Here you are not bothering to point out the bug, but
are instead dressing it as an "exercise". This removes the substance from your
argument.

Phil

--
Philip Potter pgp <at> doc.ic.ac.uk
 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      09-06-2007
Philip Potter said:

> jacob navia wrote:
>> Richard Heathfield wrote:
>>
>> [snip]
>>
>> Are the other bugs in C Unleashed fixed?
>>
>> Specifically in Chapter 11, page 353 you assume
>> sizeof pointer is equal to sizeof int...
>>
>> Here is the buggy code:
>> It will work when sizeof pointer is equal to sizeof int
>> (windows or linux 32 bit versions) but will crash when
>> sizeof int != sizeof pointer (windows 64 bits.
>>
>> Exercise:
>>
>> Where does Heathfield go wrong?

>
> One of your most-used arguments against your critics is that their
> arguments are not backed up by substance. Here you are not bothering
> to point out the bug, but are instead dressing it as an "exercise".
> This removes the substance from your argument.


I don't think that's such a big deal, actually; he does, after all, give
a pretty reasonable summary of the bug. But Mr Navia is referring to an
error which was reported, acknowledged, and entered into the book's
errata list ***seven years*** ago.

Perhaps, for an encore, Mr Navia would like to attack Messrs Kernighan
and Ritchie for the errors to be found in "The C Programming Language",
2nd edition. He can find ammunition here:
http://cm.bell-labs.com/cm/cs/cbook/2ediffs.html

In a rare fit of energy, I have just spent a little time copying the "C
Unleashed" errata to my current Web site, and I've taken the
opportunity to add one or two extra notes. Suspicious minds should note
that the int/int * erratum is present on the original errata page cited
in the book itself, and that page is hosted on a site to which I have
not had write access for several years, as I have had cause to mention
once or twice before in this group.

The new errata site is here:

http://www.cpax.org.uk/prg/portable/...rata/index.php

Plenty there for Mr Navia to criticise. In the meantime, perhaps the
rest of us can move on to more interesting subjects, such as C
programming.

(I am, of course, always glad to hear of CU bugs that are /not/ present
on the errata list. Well, not glad, but you know what I mean.)

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
 
Reply With Quote
 
jacob navia
Guest
Posts: n/a
 
      09-06-2007
Richard Heathfield wrote:
> I don't think that's such a big deal, actually; he does, after all, give
> a pretty reasonable summary of the bug. But Mr Navia is referring to an
> error which was reported, acknowledged, and entered into the book's
> errata list ***seven years*** ago.


Excuse me I wasn't aware of that.
 
Reply With Quote
 
Joachim Schmitz
Guest
Posts: n/a
 
      09-06-2007
"Richard Heathfield" <(E-Mail Removed)> schrieb im Newsbeitrag
news:(E-Mail Removed)...
> In a rare fit of energy, I have just spent a little time copying the "C
> Unleashed" errata to my current Web site, and I've taken the
> opportunity to add one or two extra notes. Suspicious minds should note
> that the int/int * erratum is present on the original errata page cited
> in the book itself, and that page is hosted on a site to which I have
> not had write access for several years, as I have had cause to mention
> once or twice before in this group.
>
> The new errata site is here:
>
> http://www.cpax.org.uk/prg/portable/...rata/index.php
>
> Plenty there for Mr Navia to criticise. In the meantime, perhaps the
> rest of us can move on to more interesting subjects, such as C
> programming.
>
> (I am, of course, always glad to hear of CU bugs that are /not/ present
> on the errata list. Well, not glad, but you know what I mean.)

Found a problem with the errata: on
http://www.cpax.org.uk/prg/portable/...rata/ech13.php there's an
orphaned hyperlink to
http://www.cpax.org.uk/prg/portable/...a/896213nw.zip

And on the main page you mention "the old site" without hyperlinking to it

Interesting reading BTW, made me curious for the book itself...

Bye, Jojo


 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      09-06-2007
Joachim Schmitz said:

<snip>

> Found a problem with the errata: on
> http://www.cpax.org.uk/prg/portable/...rata/ech13.php
> there's an orphaned hyperlink to
> http://www.cpax.org.uk/prg/portable/...a/896213nw.zip


Whoops! Fixed. Thanks.

> And on the main page you mention "the old site" without hyperlinking
> to it


That is deliberate. The old site should be considered dead, really. I'm
astounded that it has remained "up" all these years, since nobody is
paying for it! It is outside my control, and its plug could be pulled
at any time, so I don't want to draw any more attention to it than is
absolutely necessary.

> Interesting reading BTW, made me curious for the book itself...


It had not occurred to me that a bug list could be a selling point.

Unfortunately, the book went out of print a while back; so, if you want
to read it, you'll have to content yourself with a second-hand copy.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      09-06-2007
Richard Heathfield wrote:
> Joachim Schmitz said:
>

.... snip about C Unleashed ...
>
>> Interesting reading BTW, made me curious for the book itself...

>
> It had not occurred to me that a bug list could be a selling point.
>
> Unfortunately, the book went out of print a while back; so, if you want
> to read it, you'll have to content yourself with a second-hand copy.


Ahh - so my copy is attaining antique status and elevated value.
Just like me. I think I have peaked, but hopefully CU hasn't yet.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
Joachim Schmitz
Guest
Posts: n/a
 
      09-06-2007
"Richard Heathfield" <(E-Mail Removed)> schrieb im Newsbeitrag
news:(E-Mail Removed)...
> Unfortunately, the book went out of print a while back; so, if you want
> to read it, you'll have to content yourself with a second-hand copy.

Amazon still liste a few dealers (3, to be exact) that sell it as being new.

Bye, Jojo


 
Reply With Quote
 
Joachim Schmitz
Guest
Posts: n/a
 
      09-06-2007
"Richard Heathfield" <(E-Mail Removed)> schrieb im Newsbeitrag
news:(E-Mail Removed)...
> Joachim Schmitz said:

<snip>
>> And on the main page you mention "the old site" without hyperlinking
>> to it

>
> That is deliberate. The old site should be considered dead, really. I'm
> astounded that it has remained "up" all these years, since nobody is
> paying for it! It is outside my control, and its plug could be pulled
> at any time, so I don't want to draw any more attention to it than is
> absolutely necessary.

I found it anyway

Bye, Jojo


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments