#include <stdio.h>This way of writing C is quite similar to assembly--in fact, there's a one-to-one correspondence between lines of C code written this way and machine language instructions. More complicated C, like the "for" construct, expands out to many lines of assembly.
int main() {
int i=0;
if (i>=10) goto byebye;
printf("Not too big: i==%d\n",i);
byebye: printf("All done!\n");
}
#include <stdio.h>Try this out in NetRun!
int main() {
int i=0;
goto test;
start: {
printf("In loop: i==%d\n",i);
}
i++;
test: if (i<10) goto start;
printf("All done!\n");
}
Normal C |
Expanded C |
if (A) { ... } |
if (!A) goto END; { ... } END: |
if (!A) { ... } |
if (A) goto END; { ... } END: |
if (A&&B) { ... } |
if (!A) goto END; if (!B) goto END; { ... } END: |
if (A||B) { ... } |
if (A) goto STUFF; if (B) goto STUFF; goto END; STUFF: { ... } END: |
while (A) { ... } |
goto TEST; START: { ... } TEST: if (A) goto START; |
do { ... } while (A) |
START: { ... } if (A) goto START; |
for (i=0;i<n;i++) { ... } |
i=0; /* Version B */ goto TEST; START: { ... } i++; TEST: if (i<n) goto START; |
for (i=0;i<n;i++) { ... } |
i=0; /* Version A */ START: if (i>=n) goto END; { ... } i++; goto START; END: |