Looping straight-line code.

From: R. Clayton <rclayton_at_monmouth.edu>
Date: Thu, 11 Sep 2014 22:22:19 -0400
Here is some straight-line code that loops courtesy of setjmp-longjmp:

  $ cat looper.c
  #include <setjmp.h>
  #include <stdlib.h>
  #include <stdio.h>

  int
  main() {

    jmp_buf env;
    int i = 0;
    const int n = 5;

    if (setjmp(env) >= n)
      exit(EXIT_SUCCESS);

    printf("i = %d.\n", ++i);

    longjmp(env, i);
    }

  $ gcc -o looper looper.c

  $ ./looper
  i = 1.
  i = 2.
  i = 3.
  i = 4.
  i = 5.

  $
Received on Thu Sep 11 2014 - 22:24:07 EDT

This archive was generated by hypermail 2.2.0 : Sun Sep 14 2014 - 14:26:44 EDT