home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 1 / RISC_DISC_1.iso / pd_share / code / unixlib / !UnixLib / test / c / allocatst2 < prev    next >
Encoding:
Text File  |  1994-03-08  |  843 b   |  70 lines

  1. #include <stdlib.h>
  2. #include <time.h>
  3. #include <stdio.h>
  4. #include <setjmp.h>
  5.  
  6. #include "alloca.h"
  7.  
  8. #define ASIZE 2048
  9. #define ACNT  64
  10.  
  11. static int acnt, ajmp;
  12.  
  13. static jmp_buf ajmb;
  14.  
  15. static void
  16. allocatst (void)
  17. {
  18.   int *b;
  19.   register int i;
  20.  
  21.   srand (time (0));
  22.  
  23.   b = alloca (ASIZE);
  24.  
  25.   for (i = 0; i < (ASIZE >> 2); i++)
  26.     b[i] = rand ();
  27.  
  28.   printf ("%x\t", b);
  29.  
  30.   b = alloca (ASIZE);
  31.  
  32.   for (i = 0; i < (ASIZE >> 2); i++)
  33.     b[i] = rand ();
  34.  
  35.   printf ("%x\n", b);
  36.  
  37.   if (++acnt == ACNT)
  38.     {
  39.       if (ajmp)
  40.     longjmp (ajmb, -1);
  41.       else
  42.     return;
  43.     }
  44.  
  45.   allocatst ();
  46. }
  47.  
  48. int
  49. main ()
  50. {
  51.   acnt = 0, ajmp = 0;
  52.   allocatst ();
  53.  
  54.   if (setjmp (ajmb))
  55.     goto next;
  56.  
  57.   acnt = 0, ajmp = -1;
  58.   allocatst ();
  59.  
  60. next:acnt = 0, ajmp = 0;
  61.   allocatst ();
  62.  
  63.   if (setjmp (ajmb))
  64.     exit (0);
  65.  
  66.   acnt = 0, ajmp = -1;
  67.   allocatst ();
  68.   return 0;
  69. }
  70.