[Cfp-interest] exceptional macro

David Hough CFP pcfp at oakapple.net
Tue May 13 14:24:54 PDT 2014


Here's what I came away with after our morning discussion.
Still to come: application to the previous example.


Exceptional Macro

 FE_EXCEPTIONAL( expression or compound statement, exception1, exception2, ...)

is a special macro, almost a varargs function.   
It evaluates the expression or compound statement,
and returns a non-zero int if any of the listed exceptions arose in the
course of the computation, and a zero int otherwise.
The non-zero int might be an implementation-dependent encoding of the listed
exceptions that arose, taking into account sub-exceptions.
Flags and traps for the listed exceptions
are the same after execution as before.
(What about other side effects?)

It's intended to be used like any other conditional expression,

 if FE_EXCEPTIONAL(expr, exception) {
  exceptional case code
 } else {
  nonexceptional case code
 }
 
 FE_EXCEPTIONAL(expr, exception) ? exceptional case code : nonexceptional case code
 
 switch FE_EXCEPTIONAL(expr, exception) {
 case ...
 }


Since common usages would include

 if FE_EXCEPTIONAL( expr, exception) {
  exceptional case code
 } else {
  a = expr ;
 }
 
 FE_EXCEPTIONAL(expr, exception) ? exceptional case code : a = expr;

optimizing compilers would be expected to handle these cases
without unnecessary recomputation. 


FE_EXCEPTIONAL is intended to impart the flexibility of C++ try/catch without
damaging C syntax or supporting the full generality of C++ try/catch.
FE_EXCEPTIONAL is not a function; its arguments can include a compound
statement and the expression or compound statement is not to be 
evaluated outside the macro.
It seems much better to avoid scope issues by having
expressions and labels exist within normal
C syntax than somehow grafted onto pragmas.

We could note than a corresponding construct

 FE_SIGNALING( expression or compound statement, signal1, signal2, ...)

could have commensurate benefits for non-numeric programs: hiding all
the complication of setting up, using, and tearing down local signal handlers
by making the compiler and operating system figure it out.
But that's not our case.

(By considering signals I came up with FE_SIGNALING and then
the name FE_EXCEPTIONAL, rather than FE_TRYCATCH,
but maybe somebody else has a better idea.)


More information about the Cfp-interest mailing list