Saturday, July 14, 2007

Semantic Notes

* The Interpretation of Numbers
In the occurrence of numbers in C codes, note the default data types of them, since this would affect the conversion of data types in the expression.
- Integer number is of signed int.
- float point number is of double, not float.

* Expression Evaluation Sequence
Only four operators in C, &&, ||, ?: and , specify an order of evaluation. All other operators evaluate their operands in undefined order. The assignment operator does not guanantee the evaluation order. Like y[i] = x[i++];

* The meaning of 0
- It is the NULL pointer with (void *) type and its content can not be referenced.
- It is the binary number of the ending symbol of a string, '\0'.
- It could be casted to the pointer to any data type and perform some calculation, like
    (size_t)((char *)&(((Type *)0)->partx) - (char *)((Type *)0))
- Complement of 0: unsigned int compzero = ~0;

Reference:
Andrew Koenig, "C Traps and Pitfalls", AT&T Bell Lab

No comments: