Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

k&r

Name: Anonymous 2010-09-02 0:50

should i read k&r

Name: Anonymous 2010-09-02 0:59

>>1
The real question is "Why haven't you read K&R yet?"

Name: Anonymous 2010-09-02 4:55

OP here, i ask because it's hard for me to get into because i can't get any of the programs with EOF in them to end. am i missing something?

i'm using cc and os x

Name: Anonymous 2010-09-02 5:08

>>3
You're missing some capital letters and a sage.

Name: Anonymous 2010-09-02 6:18

>>3
^D, ``faggot''.

Name: Anonymous 2010-09-02 6:29

K&R
Pronounced 'kander'.

Name: Anonymous 2010-09-02 9:01

What is recommended to read after K&R?
also, I already grabbed a copy of SICP.

Name: Anonymous 2010-09-02 10:09

>>7
Probably ISWM, which is highly topical nowadays. Despite a focus on being accessible for inexperienced readers, I suspect it will appeal to veterans as well.

Name: Anonymous 2010-09-02 10:38

SICP

Name: Anonymous 2010-09-02 11:26

>>7
What is recommended to read after K&R?

There is no *after* K&R, you cant get higher than that for C

There are some books you should also have on C
-Expert C Programming (aka Deep C Secrets)
-C Unleashed (out of print)
-C: a Reference Manual (Harbison/Steele)

Name: Anonymous 2010-09-02 11:38

>>10
-Expert C Programming (aka Deep C Secrets)
For comedy value, I hope? That book is terrible!

Name: Anonymous 2010-09-02 13:00

>>8
ISWM
never heard of that and can't find anything on the net about it right away.
also, http://www.iso-9899.info/wiki/Books .

Name: Anonymous 2010-09-02 13:01

>>11
The book was meant to be funny because people learning an advanced systems language like C as a first language often is funny. Sort of like people learning to fly without going to ground school first, you can imagine the results of people learning theory of aerodynamics and mechanics of engine handling by hands on experience rather than being taught the theory beforehand.

Name: Anonymous 2010-09-02 13:10

Funny thing is most WW2 pilots learned exactly that way.
Most people learn to drive the same way too.
Dry theory is a great way to kill interest in people. Hands on however fires their interest, and makes them more willing to sit through the major boring shit later.

Name: Anonymous 2010-09-02 13:48

>>13
Hey, wet-pants! This isn't the Women's Auxiliary Balloon Corps, you're in the Twenty-Minuters now.

Name: Anonymous 2010-09-02 14:28

I just started reading K&R (2nd edition) and there are so many mistakes that I have to force myself to continue.

Name: Anonymous 2010-09-02 14:29

>>16
Oh yeah?

Name: Anonymous 2010-09-02 14:38

I just started reading K&R (2nd edition) and there are so many mistakes that I have to force myself to continue.

you just earned your kamikazi pilot wings

Name: Anonymous 2010-09-02 21:08

>>17
oh yeah.

for example, in the tutorial chapter the output for the fahrenheit/celsius program is wrong. it starts with 1 whereas it should start with 0

or look at this line:
You should note carefully
that '\n' is a single character, and in expressions is just an integer; on the other hand, '\n' is
a string constant that happens to contain only one character.

Name: Anonymous 2010-09-02 21:14

>>16,19
I'm guessing you guys downloaded the shitty typed-up-in-WOrd version instead of the LaTeX typeset one or the scan.

Name: Anonymous 2010-09-02 21:20

>>19
for example, in the tutorial chapter the output for the fahrenheit/celsius program is wrong. it starts with 1 whereas it should start with 0
(pg #12)
no its not, fahr is the increment variable, its instantiated with the variable lower and lower is instantiated with 0

or look at this line:
You should note carefully that '\n' is a single character, and in expressions .... blah

ok, whats wrong with that line?

Name: Anonymous 2010-09-02 21:32

>>21
'\n' is a char, which in C is just an integer-type, and therefore yields an integer-value when being evaluated.
the statement, though, that '\n' is "on the other hand a string constant that happens to contain only one character." is just wrong. the only string-constant that only contains one charactar in C is "", which contains '\0' as its only element of type char.

Name: Anonymous 2010-09-02 21:32

>>21
the program itself isn't wrong, but the example output they printed, right after "1.2 Variables and Arithmetic Expressions" the first line is

1    -17
instead of
0    -17

and the second '\n' should be "\n"

Name: Anonymous 2010-09-02 21:35

>>22
actually the statement is right apart from the quotes, since a c string is always 0 terminated. so the zero length string is "" or { 0 } in array notation. the 0 termination itself isn't part of the c string by definition.

Name: Anonymous 2010-09-02 21:51

>>22
'\n' is a char data type which is one byte long, it is not equal to an int

"" is not a char but an array of chars with only the terminating /n

Name: Anonymous 2010-09-02 22:03

K&R is written by the people who invented C

It has no mistakes

The implementations have mistakes

Name: Anonymous 2010-09-02 22:04

>>22
I want to further point out that K&R is a book for teaching experienced programmers how to use C well, its not for someone new to this kind of low level programming. I recommend "C Primer Plus" or "Beginning C from Novice to Professional" for someone new to programming.

Name: Anonymous 2010-09-02 22:04

>>25
first, nobody ever said it was equal to an int. second, it is the terminating '\0', not /n (whatever that means, anyway).

Also, back to Sage101, please.

Name: Anonymous 2010-09-02 22:05

>>25
A char is not guaranteed to be one byte long (the only thing the standard guarantees is that it can take at least 255 different values), and nobody is saying it's ``equal to an int''.
A string literal is not strictly the same thing as an array of chars with a terminating '\0' (which I assume is what you meant when you said ``/n'').

If people bought their books instead of all downloading the same crappy PDF scan we wouldn't even be having this discussion.

Name: Anonymous 2010-09-02 22:08

>>20
I'm guessing you guys downloaded the shitty typed-up-in-WOrd version instead of the LaTeX typeset one or the scan.

I downloaded 3 versions of the 2nd edition and all 3 of them have the same errors. Just came across another one. Chapter 1.5.4, the wc example:

#include <stdio.h>

#define IN 1 /* inside a word */
#define OUT 0 /* outside a word */

/* count lines, words, and characters in input */
main()
{
    int c, nl, nw, nc, state;
    state = OUT;
    nl = nw = nc = 0;
    while ((c = getchar()) != EOF) {
            ++nc;
        if (c == '\n')
            ++nl;
        if (c == ' ' || c == '\n' || c = '\t') // Should be c == '\t'
            state = OUT;
        else if (state == OUT) {
            state = IN;
            ++nw;
        }
    }
    printf("%d %d %d\n", nl, nw, nc);

}


Can someone with a hard copy confirm this?

Name: Anonymous 2010-09-02 22:10

>>29
In fact, a char is the smallest addressable datatype in C (on your CPU, in fact) and therefore always equal to a byte!! What that means is, that a byte does not neccessarily contain 8 bits.
Also, ever wondered why sizeof (char) is defined to be 1?

Name: Anonymous 2010-09-02 22:12

>>29
A char is guaranteed to be one byte. However, one byte isn't guaranteed to be 8 bits.

Name: Anonymous 2010-09-02 22:12

>>31
Never mind explaining, C's integer types are just plain retarded.

Name: Anonymous 2010-09-02 22:13

>>30
no mistakes in the hard copy.

protip: use /* ... */ instead of // ...

Name: Anonymous 2010-09-02 22:14

>>31-32
Both of you need to read the standard. It's true that a byte is not guaranteed to be eight bits, but a char is not defined to be a byte either.

Name: Anonymous 2010-09-02 22:19

Name: Anonymous 2010-09-02 22:20

>>35
No, you need to read the standard.

6.5.3.4p2 "The sizeof operator yields the size (in bytes) of its operand [...]."
6.5.3.4p3 "When applied to an operand that has type char, unsigned char, or signed char, (or a qualified version thereof) the result is 1."

Now kindly fuck off, ``faggot''.

Name: Anonymous 2010-09-02 22:20

char is not guaranteed to be exactly 8 bits but as >>29 said it is guaranteed to be AT LEAST 8 bits.

Name: Anonymous 2010-09-02 22:27

I was in Barnes & Noble the other day buying some books and I realized I didn't have a copy of K&R around anymore. I picked up the book along with a few others and went up to the check out. I could not believe it when they rang the book up for 60 fucking dollars. Just for fun I compared this book to the Programming Python book located nearby on the shelf, which is more than 1100 pages-- a massive reference book produced fairly recently (more recently than K&R C anyway). By comparison, this book was barely a scrap of Programming Python, and yet they want 60$ for it. Sucks for Barnes and Noble, they could have sold me that book for 30 dollars which is probably more than its worth in the grander scheme of things anyway, but instead they tried to rape me for buying an old classic book to brush up on my C. Shameful. Can you imagine if they wanted like 60$ for Hamlet or something? That's what it felt like.

Name: Anonymous 2010-09-02 22:31

>>39
K&R will be in the public domain in about a century. It will be cheaper then.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List