Deconstructing "K&R C"
c.learncodethehardway.org
Deconstructing "K&R C"
1–10 of 136 posts
Re: Deconstructing "K&R C"
#2Re: Deconstructing "K&R C"
#3This is just the first section of the chapter, right? It seems a little premature to be distributing or discussing it here.
Re: Deconstructing "K&R C"
#4Re: Deconstructing "K&R C"
#5Isn't "assert(line != NULL && longest != NULL && "memory error");" a bug in Zed's example code?
Re: Deconstructing "K&R C"
#6Isn't "assert(line != NULL && longest != NULL && "memory error");" a bug in Zed's example code?
Re: Deconstructing "K&R C"
#7Isn't "assert(line != NULL && longest != NULL && "memory error");" a bug in Zed's example code?
Re: Deconstructing "K&R C"
#8The author notes that "the second this function is called...without a trailing '\0' character, then you'll hit difficult to debug errors", but no function with that signature could possibly work in this case.
The built-in "strcpy" function has the exact same limitation. Does the author have a problem with it as well? Null-termination is a fundamental concept of C strings; there's no reason to shield C students from it.
The other example of "bugs and bad style" in this "destruction" of K&R C is a minor complaint about not using an optional set of braces.
I hope the remainder of the [incomplete] chapter demonstrates some actual bugs in the book's code, because it currently doesn't live up to the first paragraph's bluster.
Re: Deconstructing "K&R C"
#9On careful examination of his example code, you can see that there's no attempt to terminate the buffer (though he misidentifies it as an "off by one" error). Throwing arbitrary buffers into functions meant for null-terminate strings will cause errors everywhere, not just in K&R example code. In the next chapter, does he use strcpy in the same example and use that error to say that we should deprecate the entire standard library?
On a more nit-picky note, the 'triple-equality trick' the author derides is a common C idiom and one every C programmer should be familiar with. Perhaps it doesn't belong in the first chapter, but it definitely belongs in any C manual.