Class Notes for Week Ending 11/6/09

By popular request, and since many of you have never seen a goto before, here is how to write a for loop using only if's and goto's:

#include <stdio.h>

int main( void )
{
    int i;
#if 0
    for (i = 0; i < 64; ++i) {
        printf ("%x\n", 0xdeadbeef >> i);
    }
#endif
    i = 0;
loop:
    if (i >= 64) {
        goto loop_break;
    }
    printf ("%x\n", 0xdeadbeef >> i);
    ++i;
    goto loop;
loop_break:
    return 0;
}

Also, here is a link to the latest (as of this posting) revision of the C99 standard:

http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf

It is the real McCoy and is more comprehensive than the K&R book, although less user friendly.

Back to top
blog/class_notes_for_week_ending_11_6_09.txt · Last modified: 2009/11/04 22:52 by jeffk