The features listed below may not be strange, but some are interesting.
1) a [2] is equivalent to 2 [a]
"Aabbccdd" [5] is equivalent to 5 ["aabbccdd"]
This feature can be used for arrays, pointers, and strings, but cannot be used for variable definition. On the K & r c Programming language 217 page, we will introduce this.
2) binary and ternary composite characters
Http://en.wikipedia.org/wiki/Digraphs_and_trigraphs
String Literal Value ??! Will be considered as |, so be careful when two question marks appear in the string at the same time. Binary composite characters are introduced in C99, for example, <: equivalent [
3) Duff's Device
Http://en.wikipedia.org/wiki/Duff%27s_device
Switch and while are staggered. Similar code
4) Same Name and surname
The C traps and defects are described in detail.
5) a [I ++] = I;
This seems to depend on the implementation of a specific compiler. In Xcode, I first assigned an I value to a [I] And then operated on I ++. Be careful with this type of code. If you find that ++ appears in other expressions or as a parameter in code review, you must immediately move it out as a separate statement, and be careful when driving the ship.
6) sizeof
Sizeof (x), x can be an expression or type name. If it is an expression, int x = 1; size_t sz = sizeof (x ++); X will not increase. T * p = NULL; p = malloc (sizeof * p); p has not been mentioned, and the K & R holy book also speaks.
Sizeof unary-expr; sizeof (typename); The unary expression can have no parentheses, which is mentioned in the syntax section of the holy book. For example, size_t f = sizeof 99;
7) Be careful with macro definition
For example: # define FOO (a, B) (a + B)/(1-a) If FOO (bar ++, 4) is called in this way, it is automatically added twice. Of course, it is very clear to expand the macro.
References:
Http://www.steike.com/code/useless/evil-c/
C traps and Defects