summaryrefslogtreecommitdiffstats
path: root/software
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2011-06-26 14:53:31 -0400
committerbnewbold <bnewbold@robocracy.org>2011-06-26 14:53:31 -0400
commitb35e9606846636b7505efb078b16f34deb42f961 (patch)
treec6577a33c29e4fd4e02b738ee1f2b09a1a5355af /software
parent85a603e6421aa9241632f1405d4f31ef06fcaff6 (diff)
downloadknowledge-b35e9606846636b7505efb078b16f34deb42f961.tar.gz
knowledge-b35e9606846636b7505efb078b16f34deb42f961.zip
old c notes
Diffstat (limited to 'software')
-rw-r--r--software/c.page44
1 files changed, 44 insertions, 0 deletions
diff --git a/software/c.page b/software/c.page
new file mode 100644
index 0000000..910a5de
--- /dev/null
+++ b/software/c.page
@@ -0,0 +1,44 @@
+
+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).
+