C

Contents
      1. C Pitfalls
              1. Evaluation order:
              2. Stack vs. heap allocation:
              3. Internal static vars
              4. Macro expansion
              5. More:

C Pitfalls

Evaluation order:
 printf("%d %d %d %d", i, a[i], i++, i);
produces an undefined result
Stack vs. heap allocation:
 void foo() {
     int a[2];
     char *ch = new char; // (In C++) never freed
     return a;
 }
 b = foo(); // points to free memory!
Internal static vars
	time_t now = time(NULL);
	char *time1 = ctime(&now);
	sleep(1);
	now = time(NULL);
	char *time2 = ctime(&now);
It's now always time1==time2, because they point to an internal static var of ctime(). While this helps preventing memory leaks, it makes ctime - like many other library functions - be not thread save.
Macro expansion
 #define min(X,Y) ((X) < (Y) ? (X) : (Y))
The problem with this macro arises with side effects:
 min(x++, y++) 
becomes with above definition ((x++) < (y++) ? (x++) : (y++)); doubling, probably inadvertently, the side effect. This can be overcome in GNU gcc with temporal variables; type-agnostic through the use of "typeof":
 #define min(a,b) ({ typeof (a) _a = (a); typeof (b) _b = (b); _a < _b ? _a : _b; })
Cf. GNU Manual: Using the GNU Compiler Collection (GCC): Minimum and Maximum Operators in C++, Referring to a Type with typeof.
More:
The Top 10 Ways to get screwed by the C programming language

EditContents