If you aspire to learn C, you've likely heard of a book called
K&R.
K&R is the world's first genuinely good explanation of the C language.
This book became a huge success in the industry, partly because it was written by one of the original developers of the C language.
K&R is sometimes called the best-selling book in the computer industry.
This book delves into the very fine details of the C language.
Back then, there weren't any proper standards for the C language.
"It was to the extent that a C compiler was built based on this K&R."
However, the author does not recommend that you read K&R.
Actually, or rather,
you shouldn't read it.
The first reason is that the explanation is too unclear.
I think you're going to need a pretty good understanding of C to be able to read this book.
It seems the books themselves weren't intended to be read by beginners.
The second reason is the excessive use of pointers within the sample program.
For example, as an implementation of strcpy (string copy),
/* array版 */
void strcpy(char* s, char* t)
{
int i;
i = 0;
while ((s[i] = t[i]) != '\0') i++;
}
Despite the introduction of a clearer example than those shown below,
/* Pointer版 */
void strcpy(char* s, char* t)
{
while (*s++ = *t++);
}
which introduces a very convoluted example, and furthermore,
これは一見してわかりにくいように見えるが、この記法はかなり便利なものであり、
Because these idioms are commonly seen in C programs, they should be mastered.
I've noticed instances where people are deliberately encouraged to use obscure or unnecessarily complicated writing.
A third reason is that programs like these are convenient and fast, so it's worth remembering them.
It's an incredibly outdated explanation.
Such programs being fast is a thing of the past.
Currently, compilers optimize away loops of this magnitude.
Unless you write in a particularly unconventional way, there's hardly any difference in speed.
このArticleをはじめて書いたときは、Pointer版とarray版で速度差がないかどうか、
We implemented and measured our own benchmark program to verify it.
しかし、Assemblerレベルで同等なのか、最新のVC(VC2005)で試したところ、
Pointer版はCode量が約半minuteで、ジャンプ命令も1つだけに抑えられており、
array版よりもコンパクトなCodeになっていることが判明しました。
It seems there's still room for optimization using the latter approach.
However, I think arrays are fine for parts that don't need special optimization.
現代のCPUは、命令を変換し、並び替え、先読みするなど複雑な動作をしており、
Customizations at the assembly level are becoming less noticeable as speed differences.
K&R was certainly an excellent reference book back when there were no other C language guides available.
Reading K&R tends to poison my mind and make me want to write tricky programs.
Furthermore, it's explained in excessive detail, which makes it prone to unnecessary misunderstandings.
I think it's better to read K&R as a quick reference rather than a tutorial.
K&R is a slim volume, but it still covers all the features of the C language.
Not a bad thing to carry around as a mobile reference.
Furthermore, you can also use K&R's sometimes obscure explanations to check your own understanding.
If you understand K&R, you can probably say you have a decent grasp of the C language.