Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #165619

gosub.c

Newsgroups comp.lang.c
Date 2022-04-11 20:09 -0700
Message-ID <cf49401f-eae2-486d-bcf8-4550e8de5467n@googlegroups.com> (permalink)
Subject gosub.c
From luser droog <luser.droog@gmail.com>

Show all headers | View raw


Found this on my disk. I forget where/why it came from but I 
thought it was fun enough to share.


% cat gosub.c
#include <stdio.h>

#define GOSUB(target) do { *stk++ = __LINE__; goto target; case __LINE__: ;} while(0)
#define RETURN() do{ target = *--stk; goto Goto; } while(0)

int main(){
  int *stk = (int [10]){};
  int target = 0;
Goto: switch( target ){
  default:
    puts("program begins.");
    GOSUB(test_label);
    puts("program continues.");
    GOSUB(test_label);
    puts("program ends.");
    return 0;
test_label:
    puts("gosub successful.");
    RETURN();
  }
}

Back to comp.lang.c | Previous | NextNext in thread | Find similar


Thread

gosub.c luser droog <luser.droog@gmail.com> - 2022-04-11 20:09 -0700
  Re: gosub.c om@iki.fi (Otto J. Makela) - 2022-04-19 12:27 +0300
  Re: gosub.c Andreas Kempe <kempe@lysator.liu.se> - 2022-04-20 14:43 +0000
    Re: gosub.c Andreas Kempe <kempe@lysator.liu.se> - 2022-04-20 15:29 +0000
    Re: gosub.c luser droog <luser.droog@gmail.com> - 2022-04-20 13:20 -0700
    Re: gosub.c Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-04-21 07:43 -0700
  Re: gosub.c Bonita Montero <Bonita.Montero@gmail.com> - 2022-04-21 07:42 +0200
    What part of... (Well, you know the rest!) (Was: gosub.c) gazelle@shell.xmission.com (Kenny McCormack) - 2022-04-21 06:03 +0000
      Re: What part of... (Well, you know the rest!) (Was: gosub.c) Bonita Montero <Bonita.Montero@gmail.com> - 2022-04-22 07:15 +0200
        Re: What part of... (Well, you know the rest!) (Was: gosub.c) Anton Shepelev <anton.txt@g{oogle}mail.com> - 2022-04-22 11:15 +0300
          Re: What part of... (Well, you know the rest!) (Was: gosub.c) Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-04-22 02:16 -0700
            Re: What part of... (Well, you know the rest!) (Was: gosub.c) Bonita Montero <Bonita.Montero@gmail.com> - 2022-04-22 11:21 +0200
          Re: What part of... (Well, you know the rest!) (Was: gosub.c) Bonita Montero <Bonita.Montero@gmail.com> - 2022-04-22 11:18 +0200
          Re: What part of... (Well, you know the rest!) (Was: gosub.c) Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-04-25 08:09 -0700
    Re: gosub.c luser droog <luser.droog@gmail.com> - 2022-04-24 18:41 -0700

csiph-web