by Tideflat on 8/2/15, 5:46 PM with 55 comments
by cjslep on 8/2/15, 8:47 PM
switch(count % 8) {
case 0: do{ putchar('0' + (int)j);
case 7: putchar('0' + (int)j);
case 6: putchar('0' + (int)j); /* Unrolled
case 5: putchar('0' + (int)j); * for greater
case 4: putchar('0' + (int)j); * speed.
case 3: putchar('0' + (int)j); */
case 2: putchar('0' + (int)j);
case 1: putchar('0' + (int)j);
} while(--j > 0);
Without syntax highlighting, a passing glance may not recognize cases 3 through 5 are commented out.by greenyoda on 8/2/15, 6:55 PM
This is actually a very useful technique that I use all the time. It allows you to make sure that a function and any function pointers that point to it always have matching types (since you only have to change the prototype in one place - the typedef).
by m3koval on 8/3/15, 12:20 AM
"The order of allocation of bit-fields within a unit (high-order to low-order or low-order to high-order) is implementation-defined"
There is no guarantee on the order of the bits inside a bitfield. The compiler may also introduce padding, e.g. for alignment purposes. This makes bitfields unusable for unpacking binary data.
Unfortunately, you're stuck with shifting and masking to replicate the same effect.
by saurik on 8/2/15, 10:23 PM
*(const char * + char *) The type of int i is converted to 'char *' and multiplied by sizeof(char)
I am pretty certain this explanation does not make any sense: what is really happening here is that the int, for purposes of the addition, is measuring units sizeof the object being pointed to; there is no meaning I know of to adding two pointers. /* This works because "Hello"[5] == 5["Hello"].*/
At this point, you could really just say the following: /* This works because a[b] == *(a + b), and addition is commutative. */
by skarap on 8/2/15, 7:59 PM
struct items_with_header { int header_field1; unsigned int length; double array[]; };
Then allocate enough memory and use the struct to access it.
Used it once in a hash-table implementation.
by white-flame on 8/3/15, 1:52 AM
by HelloNurse on 8/3/15, 8:31 AM
by andrewchambers on 8/2/15, 11:57 PM
by drauh on 8/2/15, 8:40 PM
by thwest on 8/2/15, 7:45 PM
by nemesisrobot on 8/3/15, 2:34 AM
by halosghost on 8/2/15, 7:45 PM
Umm, that's really not that restrictive. Use `clang -Weverything -std=c11 main.c` if you want strict warnings.
by fit2rule on 8/2/15, 8:41 PM