All pastes #207640 Raw Edit

Anonymous

public text v1 · immutable
#207640 ·published 2006-10-18 03:07 UTC
rendered paste body
I feel that there should be a greater focus on dynamically allocated arrays, including multidimensional arrays. Currently they are only given a very small mention in the context of buffers of bytes. This should also introduce why using sizeof in malloc calls can be important. Often programs require the use of some arbitrary-sized array whose size is known only at runtime. Sometimes assignments will specify the maximum size you can expect, but using static allocation in these cases can lead to brittle or inefficient code (though this may be more of a stylistic complaint in many cases).

There should also be some more time spent on strings and string functions. Coming from the "easy" string library of C++, there's a temptation to simply throw string functions at something until it does what you want, without understanding what's really going on. In particular, the difference between the str-style and strn-style functions should be shown, as well as introducing the common unbounded copy (buffer overflow) bug. Due to the way strings work in C, it may be more logical to place this section after the section on pointers.

The short section explaining the memory layout of structs seems superfluous for the document's intended level. I can't really see where someone moving from C++ to C would need to know this initially unless they were dealing with a very specific problem.

Simply saying "It is usually best to place [the increment] operator after the variable" skips informing the reader of the important difference between pre and post operators. Misunderstanding how these operators work can lead to bugs.

There are two small errors where "#declare" is used where "#define" was intended. Along those lines, malloc's in the example code should be explicitly cast to their intended pointer types.

Since conversion from C++-style strings to C-strings is discussed, you may also want to discuss the differences between new/delete and malloc/free.