446,386 Members | 1,793 Online
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,386 IT Pros & Developers. It's quick & easy.

# Looking for a C textbook with emphasis on data types

 P: n/a I am supposed to teach an introductory C course with an unusual slant, and have trouble finding an appropriate textbook. The course will begin traditionally enough with variables, loops, conditionals, structures, pointers and fopen/fclose. Beyond that, however, every course and textbook I had seen is heavy on data *structures*, and touches on other topics lightly if at all. Whereas I need to stress data *types*, converting them one into the other, and bit manipulation. By the end of the course I do not care if my students know what a linked list is, let alone a binary tree, but they must have good understanding of ASCII, binary and hexadecimal. For example, it must clear to them why number 353 is actually stored as 0x01 0x61 if it's and INT, but 0x33 0x35 0x33 if it's a CHAR*. Or why converting a numeric CHAR into an INT involves subtracting 48 -- and not 30, as previous example might suggest. Is there a textbook with such emphasis on data types, bits, and hexadecimal, or am I doomed to writing my own? Jul 14 '06 #1
20 Replies

 P: n/a il***@rcn.com said: By the end of the course I do not care if my students know what a linked list is, let alone a binary tree, but they must have good understanding of ASCII, Why? That has nothing to do with C. binary and hexadecimal. For example, it must clear to them why number 353 is actually stored as 0x01 0x61 if it's and INT, There is no INT type in C. 353 might be stored as 0x0161, but it might be stored as 0x6101, 0x00006101 (i.e. in 4 octets), or as 0x61010000 (little endian, four octets to the int), or in any of a zillion other ways. but 0x33 0x35 0x33 if it's a CHAR*. C has no CHAR type. To store the characters '3', '5', and '3', you need three bytes of storage. A pointer to the first of these characters will /not/ have the value 0x333533 (unless by some astounding coincidence). Or why converting a numeric CHAR into an INT involves subtracting 48 -- It doesn't. If you mean turning '4' into 4 or '6' into 6, it involves subtracting '0', not 48. and not 30, as previous example might suggest. Is there a textbook with such emphasis on data types, bits, and hexadecimal, or am I doomed to writing my own? Oh my word. Please, please, please don't write your own, until you understand what you're talking about. -- Richard Heathfield "Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.uk email: rjh at above domain (but drop the www, obviously) Jul 14 '06 #2

 P: n/a il***@rcn.com wrote: I am supposed to teach an introductory C course with an unusual slant, and have trouble finding an appropriate textbook. The course will begin traditionally enough with variables, loops, conditionals, structures, pointers and fopen/fclose. Beyond that, however, every course and textbook I had seen is heavy on data *structures*, and touches on other topics lightly if at all. Are you talking about any C book or some data structures book ? >Whereas I need to stress data *types*, Is it required ? converting them one into the other, and bit manipulation. By the end of the course I do not care if my students know what a linked list is, let alone a binary tree, but they must have good understanding of ASCII, binary and hexadecimal. Which of these is 'C' ? >For example, it must clear to them why number 353 is actually stored as 0x01 0x61 if it's and INT, Is it ?? its NEWS. What if you are using a machine with little endian byte ordering ? >but 0x33 0x35 0x33 if it's a CHAR*. How can number 353 be char * ?? >Or why converting a numeric CHAR into an INT involves subtracting 48 -- and not 30, as previous example might suggest. Who told you to subtract 30 ? You have to subtract ' 0'. And you would have missed ' 0x' while you were reading. It should have been 0x30. Is there a textbook with such emphasis on data types, bits, and hexadecimal, or am I doomed to writing my own? Ooops... No please,,, for god's sake. Go and read " the holy book" , The C programming language, by K & R. Jul 14 '06 #3

 P: n/a "arun" writes: >Is there a textbook with such emphasis on data types, bits, andhexadecimal, or am I doomed to writing my own? Ooops... No please,,, for god's sake. Think of the children!!! Jul 14 '06 #4

 P: n/a but 0x33 0x35 0x33 if it's a CHAR*. How can number 353 be char * ?? If it's a character string "353" Jul 14 '06 #5

 P: n/a Or why converting a numeric CHAR into an INT involves subtracting 48 -- and not 30, as previous example might suggest. Who told you to subtract 30 ? You have to subtract ' 0'. 48 is decimal value of '0'. In hexadecimal it is 0x30 And you would have missed ' 0x' while you were reading. It should have been 0x30. I know that. I was bringing up an example of a mistake someone unfamiliar with hexadecimal may make. Jul 14 '06 #6

 P: n/a il***@rcn.com said: > >but 0x33 0x35 0x33 if it's a CHAR*. How can number 353 be char * ?? If it's a character string "353" Then it isn't a CHAR *. It's a string literal - a static array of four char. -- Richard Heathfield "Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.uk email: rjh at above domain (but drop the www, obviously) Jul 14 '06 #7

 P: n/a il***@rcn.com said: > >Or why converting a numeric CHAR into an INT involves subtracting 48 -- and not 30, as previous example might suggest. Who told you to subtract 30 ?You have to subtract ' 0'. 48 is decimal value of '0'. The C Standard does not guarantee this, and it is certainly not true on some systems where C is used. -- Richard Heathfield "Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.uk email: rjh at above domain (but drop the www, obviously) Jul 14 '06 #8

 P: n/a On 2006-07-14, il***@rcn.com >Or why converting a numeric CHAR into an INT involves subtracting 48 -- and not 30, as previous example might suggest. Who told you to subtract 30 ?You have to subtract ' 0'. 48 is decimal value of '0'. In hexadecimal it is 0x30 The size of a monitor is 17 inches. In hexadecimal it is 0x11. Weird how it looks to others when you assume that everyone is using your environment, huh. >And you would have missed ' 0x' while youwere reading.It should have been 0x30. I know that. I was bringing up an example of a mistake someone unfamiliar with hexadecimal may make. If you are so unfamiliar with hexadecimal that you don't know what 0x means, you shouldn't be learning programming languages, and if your students do not know what 0x means, you shouldn't teach them anything else before that. -- Andrew Poelstra To email me, use "apoelstra" at the above domain. "You people hate mathematics." -- James Harris Jul 14 '06 #9

 P: n/a il***@rcn.com wrote: >Or why converting a numeric CHAR into an INT involves subtracting 48 -- and not 30, as previous example might suggest. Who told you to subtract 30 ? You have to subtract ' 0'. 48 is decimal value of '0'. In hexadecimal it is 0x30 Oddly enough, the hexadecimal value of '0' on every one of my systems is F0. I guess I should enroll in your class so I can learn C properly. (gosh, subtracting 48, wow, I am so glad my boss never gave me that assignment because I foolishly would have subtracted 240. Maybe that's why I was never given the assignment to convert a numeric CHAR into an INT.) Jul 14 '06 #10

 P: n/a Andrew Poelstra San Diego Supercomputer Center <* We must do something. This is something. Therefore, we must do this. Jul 14 '06 #12

 P: n/a The reference document you seek is called: "INTERNATIONAL STANDARD ŠISO/IEC ISO/IEC 9899:1999 (E) Programming languages - C" and it costs \$30 or so in PDF format. Its fairly expensive in printed form, but you can probably run off a copy at Kinkos for a moderate price. The section you are interested in is: 6. Language With special ephasis on 6.5 Expressons and 6.7 Declarations Thank you. I will look into it. I should mention that most of your comments above are utter nonsense. Oversimplifications, sure. As long as one works on a system where '0' is 0x30, it is not really necessary to know that on some other system it can be something else. For that matter, when I taught calculus to non-science students, I just trashed the whole complex and fiddling limit theory, and told them that division by zero gives infinity. Not something I would do to math or physics students, but it worked in the context. Brickbats welcome. Jul 14 '06 #13

 P: n/a

 P: n/a On 2006-07-14, il***@rcn.com I should mention that most of your comments above are utter nonsense. Oversimplifications, sure. As long as one works on a system where '0' is 0x30, it is not really necessary to know that on some other system it can be something else. For that matter, when I taught calculus to non-science students, I just trashed the whole complex and fiddling limit theory, and told them that division by zero gives infinity. Not something I would do to math or physics students, but it worked in the context. Brickbats welcome. Similar to someone's "compiler for nonprogrammers" question, I have to wonder why you'd have to teach calculus to non-science (by which I assume you also mean non-math) students. The basis of C is that you can write a program and it will work on a SNES, a Commodore 64, and a robotic dragon from the future. It's a fair bit more important than you'd think to show students how different systems work, and how to make your code function no matter what the architecture. Endianness is vital, as is differently sized primitive types. Charsets were becoming less important, but now we've got internationalization and once again it's important that you aren't depending on ASCII. -- Andrew Poelstra To email me, use "apoelstra" at the above domain. "You people hate mathematics." -- James Harris Jul 14 '06 #15

 P: n/a il***@rcn.com writes: [...] Oversimplifications, sure. As long as one works on a system where '0' is 0x30, it is not really necessary to know that on some other system it can be something else. For that matter, when I taught calculus to non-science students, I just trashed the whole complex and fiddling limit theory, and told them that division by zero gives infinity. Not something I would do to math or physics students, but it worked in the context. Brickbats welcome. As long as you know that '0' is '0', you don't need to know or care that it happens to be 0x30 on your system. If you have an expression of type char, and you know that its value is in the range '0' to '9', you can get the integer value of that digit by subtracting '0': char c = '5'; int n = c - '0'; /* n == 5 */ This is guaranteed to work because the standard requires the digit characters '0' to '9' to have contiguous representations (it doesn't make the same guarantee for letters). Now, given that this is simpler, easier to remember, and more portable, why should I care that '0' == 0x30 on some but not all systems? -- Keith Thompson (The_Other_Keith) ks***@mib.org San Diego Supercomputer Center <* We must do something. This is something. Therefore, we must do this. Jul 14 '06 #16

 P: n/a >Or why converting a numeric CHAR into an INT involves subtracting 48 -- and not 30, as previous example might suggest. Who told you to subtract 30 ?You have to subtract ' 0'. 48 is decimal value of '0'. In hexadecimal it is 0x30 >And you would have missed ' 0x' while youwere reading.It should have been 0x30. I know that. I was bringing up an example of a mistake someone unfamiliar with hexadecimal may make. Students do need to know that all variables in the computer are ultimately binary, and that hexadecimal notation is a convenient way of making binary numbers readable to humans, but nothing more. They also need to know that ASCII is just an arbitrary set of mappings from integers to English-language characters. I would hope that these things are not presented as deep problems. They are just a few basic facts you need to know before you start serious C programming. Data structures. on the other hand, are interesting, because different structures have different characteristics. Some structures can be updated very easily, others only with expensive operations. Some are easy to search, others very slow. Some are easy to implement, others very tricky. -- Buy my book 12 Common Atheist Arguments (refuted) \$1.25 download or \$7.20 paper, available www.lulu.com/bgy1mm Jul 14 '06 #17

 P: n/a Andrew Poelstra wrote On 07/14/06 15:30,: [...] The basis of C is that you can write a program and it will work on a SNES, a Commodore 64, and a robotic dragon from the future. [...] If you invoke U.B. on a robotic dragon, you'll be *really* sorry about the ensuing nasal demons ... -- Er*********@sun.com Jul 14 '06 #18

 P: n/a On 14 Jul 2006 12:16:15 -0700, il***@rcn.com wrote: For that matter, when I taught calculus tonon-science students, I just trashed the whole complex and fiddlinglimit theory, and told them that division by zero gives infinity I'm not sure what you taught them, but it wasn't calculus. -- Al Balmer Sun City, AZ Jul 14 '06 #19

 P: n/a il***@rcn.com wrote: I am supposed to teach an introductory C course with an unusual slant, and have trouble finding an appropriate textbook. The course will begin traditionally enough with variables, loops, conditionals, structures, pointers and fopen/fclose. Beyond that, however, every course and textbook I had seen is heavy on data *structures*, and touches on other topics lightly if at all. Whereas I need to stress data *types*, converting them one into the other, and bit manipulation. By the end of the course I do not care if my students know what a linked list is, let alone a binary tree, but they must have good understanding of ASCII, binary and hexadecimal. For example, it must clear to them why number 353 is actually stored as 0x01 0x61 if it's and INT, but 0x33 0x35 0x33 if it's a CHAR*. Or why converting a numeric CHAR into an INT involves subtracting 48 -- and not 30, as previous example might suggest. To any student of ilya2: Run away. Now. Don't look back. Now go find a teacher who knows more than sweet Fanny Adams about the subject he's teaching, 'cause that one didn't. Richard Jul 17 '06 #20

 P: n/a "Dann Corbit"

### This discussion thread is closed

Replies have been disabled for this discussion.