473,624 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

(part 5) Dick Heathfield's book errors

Richard Heathfield said:
>>Mick Charles Beaver said:
>Hello,
>Would anyone know why the FreeBSD implementation of swab() uses an
unsigned long for its temporary variable when swapping bytes?
<snip>
although those casts are a bit pointless, aren't they?
From swab.c:

void
swab(const void * __restrict from, void * __restrict to, ssize_t len)
{
unsigned long temp;
int n;
char *fp, *tp;

n = len >1;
fp = (char *)from;
tp = (char *)to;

From Dick Heathfield's _C Unleashed_ Random() function
on pg. 406:

int Random(int n)
{
double d;

d = rand() / (RAND_MAX + 1.0);
d *= n;

return (int)d;
}

[H&S 9.8: "If a function has a declared return type T
that is not void, then the type of any expression appearing
in a return statement must be convertible to type T by
assignment, and that conversion in fact happens on return
in both Standard and traditional C.

Example
In a function with declared return type int, the
statement
return 23.1;
is equivalent to
return (int) 23.1;
which is the same as
return 23
"]

That cast in Random() is a bit pointless, isn't it? Any
defense about style or lint-like programs could equally
apply to the unnecessary casts in swab.c.

Yours,
Han from China

"It is likely that Schildt knows what a linked list is, and
it's even likely that he explains it well. What is
somewhat less likely is that his implementation is
robust." -- Richard Heathfield, 2000

Oct 29 '08 #1
8 1388
On Oct 29, 2:35*pm, Borked Pseudo Mailed <nob...@pseudo. borked.net>
wrote:

[snip]
From Dick Heathfield's _C Unleashed_ Random() function
on pg. 406:

int Random(int n)
{
* double d;

* d = rand() / (RAND_MAX + 1.0);
* d *= n;

* return (int)d;

}

[H&S 9.8: "If a function has a declared return type T
that is not void, then the type of any expression appearing
in a return statement must be convertible to type T by
assignment, and that conversion in fact happens on return
in both Standard and traditional C.

Example
* In a function with declared return type int, the
statement
* * *return 23.1;
is equivalent to
* * return (int) 23.1;
which is the same as
* * return 23
"]

That cast in Random() is a bit pointless, isn't it? Any
defense about style or lint-like programs could equally
apply to the unnecessary casts in swab.c.

Yours,
Han from China

"It is likely that Schildt knows what a linked list is, and
it's even likely that he explains it well. What is
somewhat less likely is that his implementation is
robust." -- Richard Heathfield, 2000
I can't believe I'm taking the time to respond to this trolling
jackass, but...

You *do* realize that Heathfield wasn't the only author of that book?
That he's just one of, what, 8 or 9 authors?

Again, why does Richard get all the anti-groupies, as opposed to Ben,
Steve, Keith, Eric, etc.?
Oct 29 '08 #2
John Bode wrote:
[...]
Again, why does Richard get all the anti-groupies, as opposed to Ben,
Steve, Keith, Eric, etc.?
Perhaps because Richard (as he has explained) is reluctant to
use the killfile. Can't speak for the others, but my killfile is
threatening to outgrow the SAN ...

--
Er*********@sun .com
Oct 29 '08 #3
John Bode <jfbode1...@gma il.comwrote:
Borked Pseudo Mailed <nob...@pseudo. borked.netwrote :
[snip]
Let's put it back...
Richard Heathfield said: [in another thread]
although those casts are a bit pointless, aren't they?
..._C Unleashed_ Random() function on pg. 406:
int Random(int n)
...
* return (int)d;

I can't believe I'm taking the time to respond to this
trolling jackass,
Even a 'trolling jackass' can ask valid questions. [I
guess I'm proof of that. ;-] Of course, I don't support
the motives or unconstructive manner in which 'Han from
China' asks them.
but...

You *do* realize that Heathfield wasn't the only author
of that book? That he's just one of, what, 8 or 9
authors?
True, but 7 or 8 of those 8 or 9 only appear as 'et al'
on the front cover. I believe Lawrence was the main proof
reader, however that only makes the question more valid.
[Though not necessarily interesting.]

--
Peter
Oct 29 '08 #4
On 29 Oct 2008 at 20:29, John Bode wrote:
Again, why does Richard get all the anti-groupies, as opposed to Ben,
Steve, Keith, Eric, etc.?
Perhaps because while those other people can sometimes be unhelpful,
irritating, pedantic ninnies, only Heathfield is a megalomaniac?

Oct 30 '08 #5
On Wed, 29 Oct 2008 13:29:33 -0700 (PDT), John Bode
<jf********@gma il.comwrote in comp.lang.c:
On Oct 29, 2:35*pm, Borked Pseudo Mailed <nob...@pseudo. borked.net>
wrote:

[snip]
From Dick Heathfield's _C Unleashed_ Random() function
on pg. 406:

int Random(int n)
{
* double d;

* d = rand() / (RAND_MAX + 1.0);
* d *= n;

* return (int)d;

}

[H&S 9.8: "If a function has a declared return type T
that is not void, then the type of any expression appearing
in a return statement must be convertible to type T by
assignment, and that conversion in fact happens on return
in both Standard and traditional C.

Example
* In a function with declared return type int, the
statement
* * *return 23.1;
is equivalent to
* * return (int) 23.1;
which is the same as
* * return 23
"]

That cast in Random() is a bit pointless, isn't it? Any
defense about style or lint-like programs could equally
apply to the unnecessary casts in swab.c.

Yours,
Han from China

"It is likely that Schildt knows what a linked list is, and
it's even likely that he explains it well. What is
somewhat less likely is that his implementation is
robust." -- Richard Heathfield, 2000

I can't believe I'm taking the time to respond to this trolling
jackass, but...

You *do* realize that Heathfield wasn't the only author of that book?
That he's just one of, what, 8 or 9 authors?

Again, why does Richard get all the anti-groupies, as opposed to Ben,
Steve, Keith, Eric, etc.?
I agree, I'm starting to feel neglected.

Surely there's _something_ wrong with Chapter 18?

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Oct 30 '08 #6
Peter Nilsson said:

<snip>
Even a 'trolling jackass' can ask valid questions. [I
guess I'm proof of that. ;-] Of course, I don't support
the motives or unconstructive manner in which 'Han from
China' asks them.
Neither do I, which is why I'm not answering them.

<snip>
I believe Lawrence was the main proof
reader, however that only makes the question more valid.
[Though not necessarily interesting.]
It's not a terribly interesting question. It is, however, a valid question.
The answer, however, is no - Lawrence wasn't the main proofreader. If he
had been, it would have been an even better book (but on the other hand,
we were already riding roughshod over deadlines as it was).

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Oct 30 '08 #7
Jack Klein said:

<snip>
>
Surely there's _something_ wrong with Chapter 18?
There are 29 reported errata, most being minor typographical errors.

Some of the errata were reported by a Mr J Klein. :-)

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Oct 30 '08 #8
On Oct 30, 5:32*am, Richard Heathfield <r...@see.sig.i nvalidwrote:
Peter Nilsson said:

<snip>
Even a 'trolling jackass' can ask valid questions. [I
guess I'm proof of that. ;-] Of course, I don't support
the motives or unconstructive manner in which 'Han from
China' asks them.

Neither do I, which is why I'm not answering them.

<snip>
I believe Lawrence was the main proof
reader, however that only makes the question more valid.
[Though not necessarily interesting.]

It's not a terribly interesting question. It is, however, a valid question.
The answer, however, is no - Lawrence wasn't the main proofreader. If he
had been, it would have been an even better book (but on the other hand,
we were already riding roughshod over deadlines as it was).
I had two proof readers for chapter 13.
One proofreader was an employee of the book company.
The second proofreader was...
Peter Seebach!
Maybe he was looking for IAQ entries.
;-)
Oct 30 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

97
4009
by: Master Programmer | last post by:
Thinking of learning VB.NET? New programmer? Thinking of Moving over from VB 6.0? Read on friend, let me help you make a more informed decision......... Microsoft are a pathetic company, but they have got worse over the last 5 years. Here are just a few reasons (there are many more), not to sacrifice
334
11441
by: Antoninus Twink | last post by:
The function below is from Richard HeathField's fgetline program. For some reason, it makes three passes through the string (a strlen(), a strcpy() then another pass to change dots) when two would clearly be sufficient. This could lead to unnecessarily bad performance on very long strings. It is also written in a hard-to-read and clunky style. char *dot_to_underscore(const char *s) { char *t = malloc(strlen(s) + 1); if(t != NULL)
0
1329
by: Nomen Nescio | last post by:
hay, student proggramer 19 yrs old china in computer course ben doing c proggraming cpl of months from pascal backgrond enjoyying c unleashed book posible minour buggs found in dick heathfields data structs cht buggs not on c unleashed erata witch i looked throughly grate book lerning lot frmo the c expertts pg. 348 double Loading = {0};
3
1757
by: George Orwell | last post by:
hay, Han frm china heer again... ben readin sum more c unleashed book dick heathfields book... still readin dick heathfields data structs cht but jumped ahead to chad dixons cgi proggraming cht out of interest for bit varietty... hard to focuss on length of data structs cht vry drawn out longwindded imho... small robusttness patch for pg. 400 DlExchange() function: int DLExchange(DLLIST *ItemA, DLLIST *ItemB)
8
1507
by: Nomen Nescio | last post by:
Hey, this is Ajun from a Bangladesh outsource company. Han has hired me to do the English writing for his comp.lang.c posts. The subject line has been changed, which may affect archival consistency, so if you're looking for the first two installments of this series, just run a Google Groups search for "posible minour buggs in dick heathfields book". Neither Han nor I expect to win a Pulitzer Prize anytime soon, yet we believe we're in...
4
1476
by: Nomen Nescio | last post by:
No errors to report here. It's hard work taking the nitpick microscope to the CLC Clique's book, but someone has to do it. It's occurred to me I haven't properly introduced myself. /* * 5-1-2-2-3.c * Han from China's hello-CLC program. *
1
1317
by: Lew Pitcher | last post by:
On October 29, 2008 19:30, in comp.lang.c, Nomen Nescio (nobody@dizum.com) wrote: Well, you said it: "This is nitpick central". I have a nit to pick. According to the C99 standard, the macro NULL is defined in a) <stddef.h>, /and/ b) <stdio.h>, /and/ c) <stdlib.h>
1
1417
by: Borked Pseudo Mailed | last post by:
Hey, guys. I'm still plowing through Dick Heathfield's data-structures chapter. It's like reading 100-plus pages on how to core an apple, but I'm getting there, slowly. I'm up to his HTML syntax checker in the stacks section. Noticed a corker of an error in that, but I'll leave that for one of my next posts, at which point I hope to finish up on the Heathfield data-structures chapter. Yes, it was wrong of me to compare Heathfield to...
5
1560
by: Chris M. Thomasson | last post by:
"George Orwell" <nobody@mixmaster.itwrote in message news:c6eb564c3d719950dc8bd7151040c449@mixmaster.it... Do you really think a single book provides enough weight for proper workout paraphernalia? You must be a real weakling; oh well.
0
8238
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8680
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8624
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8336
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7164
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6111
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1786
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1485
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.