blob: 96d6f04b3e7e2f15cd78e281ab85baa5593557e6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
C Programming Language
=======================
K&R Notes (unstructured)
-----------------------------
With pointer arithmatic, the type of ``foo *p`` is taken into account
automagically. Eg, ``p+3`` -> ``0xFEFE0000 + 3 * (sizeof foo)``.
Examples of tricky pointer sytax::
int *ip;
(++*p)
(*p++)
++(*p)
*(++p)
In the context of references like function declarations, only the size of the
first dimension of a multi-dimensional array is free; the others must be
specified explicitly::
void copy_2d_array(int a[][10], int b[][10]); // Ok
void copy_2d_array(int a[][], int b[][]); // Invalid
void copy_2d_array(int a[10][], int b[10][]); // Invalid
Negative indexing of arrays is "allowed" (reads ahead of the array in memory);
need to check for that case explicitly.
``_FORTIFY_SOURCE`` does what it says.
In C99 can ``int* p`` replace ``int *p``? Seems like yes.
The "update statement" of a for loop gets executed at the /end/ of every loop,
which means an iteration variable gets updated once more than might be
expected::
int i;
for(i = 0; i < 10; i++) {
}
printf("%d\n", i); // prints 10, not 9
Any 'inline' should probably be 'static' (local linkage).
Other References
------------------
"Spiral Rule" trick for understanding type/pointer definitions:
http://c-faq.com/decl/spiral.anderson.html
Notable C Libraries
---------------------
[yajl](https://github.com/lloyd/yajl) ("Yet Another JSON Library"): portable,
incremental, simple, error messages.
Zed Shaw Notes
----------------
cachegrind/callgrind: http://c.learncodethehardway.org/book/ex41.html
bstring ("better string"): http://c.learncodethehardway.org/book/ex36.html
testing: http://c.learncodethehardway.org/book/ex30.html
debug macros: http://c.learncodethehardway.org/book/ex20.html
|