<story><title>Deconstructing &quot;K&amp;R C&quot;</title><url>http://c.learncodethehardway.org/book/learn-c-the-hard-waych55.html</url></story><parent_chain></parent_chain><comment><author>tba</author><text>I&apos;m confused. What is the &quot;defect&quot; in K&amp;#38;R&apos;s &quot;copy(char to[], char from[])&quot; function?&lt;p&gt;The author notes that &quot;the second this function is called...without a trailing &apos;\0&apos; character, then you&apos;ll hit difficult to debug errors&quot;, but no function with that signature could possibly work in this case.&lt;p&gt;The built-in &quot;strcpy&quot; 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&apos;s no reason to shield C students from it.&lt;p&gt;The other example of &quot;bugs and bad style&quot; in this &quot;destruction&quot; of K&amp;#38;R C is a minor complaint about not using an optional set of braces.&lt;p&gt;I hope the remainder of the [incomplete] chapter demonstrates some actual bugs in the book&apos;s code, because it currently doesn&apos;t live up to the first paragraph&apos;s bluster.</text></comment>
<story><title>Deconstructing &quot;K&amp;R C&quot;</title><url>http://c.learncodethehardway.org/book/learn-c-the-hard-waych55.html</url></story><parent_chain></parent_chain><comment><author>blix</author><text>I don&apos;t see what the big deal is here. He throws inputs at a function not meant to handle them and gets a segfault. Isn&apos;t this more-or-less expected from all C functions?&lt;p&gt;On careful examination of his example code, you can see that there&apos;s no attempt to terminate the buffer (though he misidentifies it as an &quot;off by one&quot; error). Throwing arbitrary buffers into functions meant for null-terminate strings will cause errors everywhere, not just in K&amp;#38;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?&lt;p&gt;On a more nit-picky note, the &apos;triple-equality trick&apos; the author derides is a common C idiom and one every C programmer should be familiar with. Perhaps it doesn&apos;t belong in the first chapter, but it definitely belongs in any C manual.</text></comment>