Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83 (MC830713); site vu44.UUCP Path: utzoo!linus!decvax!ittvax!dcdwest!sdcsvax!sdcrdcf!hplabs!hao!seismo!mcvax!vu44!duk From: duk@vu44.UUCP Newsgroups: net.lang.c Subject: labels and self-modifying code Message-ID: <385@vu44.UUCP> Date: Fri, 7-Sep-84 18:52:24 EDT Article-I.D.: vu44.385 Posted: Fri Sep 7 18:52:24 1984 Date-Received: Sun, 16-Sep-84 07:48:17 EDT Organization: VU Informatica, Amsterdam Lines: 39 Who needs assembler when you can use C to write illegible, self-modifying code. The program below, slightly adapted from a program by Jack Jansen, compiles and "works" on our PDP11/44 running Unix V7. -------------------------------------------------------------------------- #include main() { func(0); func(1); } func(arg) int arg; { int *jumptab[2]; goto endofit; /* cannot use &label before it's defined */ lab0: printf("Lab 0\n"); return; lab1: printf("Lab 1\n"); return; lab2: "Lab 2\n"; endofit: jumptab[0] = lab0; jumptab[1] = lab1; *(jumptab[0] + 1) = *(lab2 + 1); goto jumptab[arg]; } -------------------------------------------------------------------------- You shouldn't give any of the options -i, -n (evidently), or -O to cc. When you give the -O flag, the optimizer throws the labels away since they are not used (it *thinks* the're not used!), and then later ld can't find them. Duk Bekema