473,788 Members | 2,754 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems with Harbison & Steele


Yesterday I embarrassed myself on sci.crypt with some incorrect C
code and corresponding claims about the language. My source was
Harbison and Steele (H&S), /C, A Reference Manual/ and I thought
I was on strong ground.

The first issue, legal inputs for toupper() and other character-
handling functions, I wrote up and sent to the appropriate
address for errata items. Dr. Harbison subsequently
acknowledged that it seems to be bug. My explanation is at:

http://groups-beta.google.com/group/...461a4bc7c3246d

or Usenet Message ID:

<8E************ *****@newssvr14 .news.prodigy.c om>.
Now I'm looking at the description of fgetc() in H&S. I have the
third and fifth editions, which both say:

It reads the next character from the stream and returns it
as a value of type int. [page 374 in the fifth edition]

When H&S describes ungetc() in the same section, the text notes
that the argument is "(converted to unsigned char)". There's
no such note about fgetc().

My reading of H&S lead me to believe that on implementations
where the char type is signed, fgetc() on a binary file could
return a negative value that is a legal character (not EOF).

The ANSI/ISO standard defines fgetc(), saying, in part:

[...] the fgetc function obtains that character as an
unsigned char converted to an int [...]

According to the standard, fgetc() returns all character values
as non-negative integers.
I that many participants here both use H&S and know the standard
well. A few questions: Am I right that the fgetc() description
in H&S is incorrect, or am I missing something? Are there other
obvious problems with H&S relating to this char-might-be-signed
business?

Finally, I expect technical books to have some errors, but I was
surprised when sci.crypt participants quickly identified code I
had written based on H&S to have undefined behavior. I had
passed a char value to toupper(). The mistake in H&S dates from
at least 1991. How could it have gone unnoticed in such a
widely-used reference?
--
--Bryan
myfirstname dot olson at acm anotherdot org
Nov 14 '05 #1
1 1725
Bryan Olson wrote:

Yesterday I embarrassed myself on sci.crypt with some incorrect C
<snip>

I that many participants here both use H&S and know the standard
well. A few questions: Am I right that the fgetc() description
in H&S is incorrect, or am I missing something? Are there other
obvious problems with H&S relating to this char-might-be-signed
business?
I don't have H&S, so no comments.
Finally, I expect technical books to have some errors, but I was
surprised when sci.crypt participants quickly identified code I
had written based on H&S to have undefined behavior. I had
passed a char value to toupper(). The mistake in H&S dates from
at least 1991. How could it have gone unnoticed in such a
widely-used reference?


7.4 Character handling <ctype.h>
The header <ctype.h> declares several functions useful for classifying
and mapping characters.166) In all cases the argument is an int, the
value of which shall be representable as an unsigned char or shall equal
the value of the macro EOF. If the argument has any other value, the
behavior is undefined.

----

7.4.2.1 The tolower function
Synopsis
1 #include <ctype.h>
int tolower(int c);

----

The function takes an int as input, but the value should either be EOF
or an unsigned char. Assuming ch != EOF.

Usage:
ch = tolower ((unsigned char)ch);

The same usage also applies to all the other ctype.h functions.
Just my two cents.

Regards,
Jonathan.

--
"Women should come with documentation." - Dave
Nov 14 '05 #2

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

Similar topics

0
3511
by: Michael Fork | last post by:
Note: I pasted the code the attachments as plain text after the message (I wasn't able to post it with an attachment...) Attached are the XSL and XML files that I am having problems with. I am trying to extract the stock information after having downloaded the HTML and converted to XML (well-formed HTML) using XSL and XPATH and am unable. I am basing what I have done so far off of...
9
2961
by: Francesco Moi | last post by:
Hello. I'm trying to build a RSS feed for my website. It starts: ----------------//--------------------- <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd"> <rss version="0.91"> ----------------//----------------------
5
2971
by: Rob | last post by:
Help me, I'm just beginning with programming in Access 2000. I've tried the http://www.mvps.org/access/api/api0001.htm but it won't work in Access. What am i doing wrong. I don't have problems with the http://www.mvps.org/access/api/api0002.htm but it only browse to folders.
7
3466
by: Wayne Aprato | last post by:
I have several Access 2003 mde databases. When I try to open them in Access 2002 I get the following error: "The Visual Basic for Applications project in the database is corrupt." Interestingly I can open the mdb files of the same 2003 databases in Access 2002 without problems. To my understanding the file formats of 2002 and 2003 are the same and this problem shouldn't exist. And why is it only the mde files that are giving the...
6
1629
by: Rick Brandt | last post by:
I am getting and setting registry values successfully with two functions from the Getz/Litwin/Gilbert book: adh_accRegGetVal and adh_accRegWriteVal. I have two cases now where these do not work under Access 2002. There is no error, the GetKey function based on adh_accRegGetVal simply returns a zero length string every time. In both cases the PC also had the 97 Runtime installed on them. Would this cause a conflict in this area? I...
5
4332
by: Matthew Hood | last post by:
Here's a interesting question for the guru's out there. I've created a VB.NET class library with a couple of forms that I have successfully got to work from within MS Access using COM interop and VBA. (Working, meaning it hasn't crashed on me yet... ;-). I Would anybody know how to take this VB.NET Winform (using it's handle, subclassing, or other means) and set it's parent to be the Access MDI client area so that it will behave as if...
14
5935
by: Arne | last post by:
A lot of Firefox users I know, says they have problems with validation where the ampersand sign has to be written as &amp; to be valid. I don't have Firefox my self and don't wont to install it only because of this, so I hope some of you gurus can enlighten me with this :) In what circumstances can the "&amp;" in the source code be involuntary changed to "&" by a browser when or other software, when editing and uploading the file to the web...
6
2678
by: Larthusza | last post by:
I've been called out of retirement to make a small database application for my local crinklies group and am a bit rusty. This is not strictly anything to do with Access per se but that is what I am using and I'm sure it is no great challenge to the excellent people who meet here. I have made my application in Delphi which uses MS Access tables and which are very small, 100 or so records, which runs across a network from a UNIX server...
2
1995
by: kj | last post by:
My favorite book on C, by far, is Harbison and Steele's "C: A Reference Manual." (In fact, it is my all-time favorite computer language reference book, irrespective of language.) Even though it is an authoritative reference manual, I found it more than readable enough to use it as the book to learn C from. This question is aimed at those who appreciate Harbison and Steele's book: among C++ books out there, which one of them deserves...
0
9656
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
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10366
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
10175
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
10112
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
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2894
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.