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


Groups > comp.std.c > #749

Continuations in C?

Date 2011-08-13 10:47 +0200
From Philipp Klaus Krause <pkk@spth.de>
Newsgroups comp.std.c
Subject Continuations in C?
Message-ID <4e463a29$0$4151$6e1ede2f@read.cnntp.org> (permalink)
Organization CNNTP

Show all headers | View raw


I would like to see functions providing continuations in the standard
library. Let's call these c() and j() for now.
Currently C provides setjmp() / longjmp() which is a restricted variant
of continuations: The continuation obtained by setjmp() is only valid as
long as the funtion that called setjmp() doesn't return. c() / j() would
be like setjmp() / longjmp() without that restriction.

Why?
1) C is increasingly used as a target language for compilers. Many of
the languages compiled to C have full continuations. Currently there are
basically two ways of compiling these to C: Continuation passing style,
which makes all funcction calls more expensive and non-portable tricks
to save and restore the stack somehow. c() / j() would provide a
portable way to implement continuations.
2) Full continuations are an extremly powerful control and useful
construct (as proven by all the things that are done using them in other
languages)). C should give programmers a way to use them. Since they
essentially are a more powerful variant of setjmp() / longjmp(), which,
in turn is a more pwoerful goto they might be considered harmful by
some. But C isn't a language designed to protect the programmers from
themselves.

c() / j() would manipulate the stack and thus should be relatively easy
to implement on systems where setjmp() / longjmp() can be implemented
easily (in particular, those that use a stack in memory and a stack
pointer, as AFAIK most implementations do). Nevertheless the feature
could be made optional and it's presence indicated by a macro, as done
e.g. with variable-length arrays in the next C standard.

So, why does C not provide full continuations?
Should, in your opinion, C provide full continuations?
Is there a chance to get them into the next C standard, and if so, how?

Philipp

Back to comp.std.c | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Continuations in C? Philipp Klaus Krause <pkk@spth.de> - 2011-08-13 10:47 +0200
  Re: Continuations in C? BGB <cr88192@hotmail.com> - 2011-08-13 03:02 -0700
    Re: Continuations in C? Philipp Klaus Krause <pkk@spth.de> - 2011-08-13 13:19 +0200
      Re: Continuations in C? BGB <cr88192@hotmail.com> - 2011-08-13 12:29 -0700
    Re: Continuations in C? Philipp Klaus Krause <pkk@spth.de> - 2011-08-15 09:49 +0200
      Re: Continuations in C? BGB <cr88192@hotmail.com> - 2011-08-16 10:53 -0700
  Re: Continuations in C? jacob navia <jacob@spamsink.net> - 2011-08-14 10:13 +0200
    Re: Continuations in C? BGB <cr88192@hotmail.com> - 2011-08-14 08:57 -0700
      Re: Continuations in C? Wojtek Lerch <wojtek_l@yahoo.ca> - 2011-08-14 23:38 -0400
        Re: Continuations in C? Philipp Klaus Krause <pkk@spth.de> - 2011-08-15 09:48 +0200
          Re: Continuations in C? BGB <cr88192@hotmail.com> - 2011-08-16 10:56 -0700
  Re: Continuations in C? Tim Rentsch <txr@alumni.caltech.edu> - 2011-08-30 15:36 -0700

csiph-web