bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: yacc.c: Extracting yysyntax_error


From: Hans Aberg
Subject: Re: yacc.c: Extracting yysyntax_error
Date: Thu, 22 Sep 2005 16:11:27 +0200


On 21 Sep 2005, at 20:43, Paul Eggert wrote:

POSIX allows portable signal handlers to do much of the stuff that
real-world signal handlers need to do, but POSIX does not specify how
C++ programs behave, and C++ does not specify how POSIX signal
handling works.  So there's no standard for how C++ exception handling
interacts with POSIX signals, and in practice I suspect it tends to be
a wild and woolly area.

C++, unlike C, admits datatypes which has constructors, and thus requires destructors, being invoked in the opposite order of the constructors. Exception handling ensures this. So here is an example how C signal handling can be converted to C++:

In C one might write:

jmp_buf env;

f() {
  signal(my_signal, handler);

  if (sejmp(env) == 0) {
    A;
  } else {
    B;
  }
}

handler(int sig) {
  /* signal stuff */
  longjmp(env, 1);
}

In C++, converting to exceptions, one might write:

class my_signal_exception {...};

f() {
  signal(my_signal, handler);

  try {
    A;
  } catch (my_signal_exception& my) {
    B;
  }
}

int handler(int sig) {
  // signal stuff
  throw my_signal_exception(...);
}

So it seems possible for POSIX to relatively simply define C++ signal handling. ALso, the code should not break the Bison C++ parser.

  Hans Aberg






reply via email to

[Prev in Thread] Current Thread [Next in Thread]