General Exception-Handling Facility and Design by Contract for C Programmers 
Author Message
 General Exception-Handling Facility and Design by Contract for C Programmers

Hello, everyone. I've been working on an exception-handling facility,
called the General Exception-Handling Facility, or GEF, for quite a
while. I started the project for the purpose of obtaining
exception-handling feature in my C programs. Although  OSF DCE contained
exception-handling as part of its RPC package, I didn't want to take the
whole DCE RPC package just to have exception-handling.

Anyway, over the years, the code has matured quite well and I even wrote
an article about it in the November 1998 issue of Dr. Dobb's. See my web


for a link to Dr. Dobb's Journal.

GEF's features are similar to the exception-handling of C++, Java, and
Eiffel, although more consistent with the behavior of Eiffel than the
others. GEF's keywords are as follows, although not limited to:

(1) gef_try
(2) gef_catch
(3) gef_finally
(4) gef_end

For control statements,

(5) gef_retry
(6) gef_throw
(7) gef_break (Unique feature)

For contract programming,

(8) gef_preconditions
(9) gef_postconditions
(10) gef_invariants

For command-line processing,

(11) --gef-preconditions={true, false}  (Default = true)
(12) --gef-postconditions={true, false}
(13) --gef-invariants={true, false}
(14) --gef-enable
(15) --gef-disable

For protecting specific handler from being disabled, use "required"
modifier for try blocks,

(16) gef_try_required

To repeat a gef_try block for a number of iterations until a try block

(17) gef_repeat_try(n)

To instruct GEF to skip the finally block because the routine will not
need to do anything special on exit,

(18) gef_try_except_finally

There are also "required" versions:

(19) gef_try_except_finally_required
(20) gef_repeat_try_required(n)
(21) gef_repeat_try_except_finally_required(n)

There are 3 separate libraries:

(22) #include <gef/ansi.h>        -lgef_ansi
(23) #include <gef/posix.h>       -lgef_posix
(24) #include <gef/pthreads.h>    -lgef_pthreads

The ANSI library is for plain vanilla C programs. The Posix library is
for non-threaded Posix operating systems (support for signal, sigaction,
sigmask, ...). The last is a PosixThreads version of GEF.

GEF can handle synchronous and asynchronous Posix signals in a
non-threaded, as well as a threaded, Posix program. However, the support
for asynchronous signals in a Posix threaded program is an extension,
since Posix does not require pthread_getspecific to be async safe,
although,for most implementations of Posix-compliant OS's,
pthread_getspecific() is async-safe. However, this restriction does NOT
apply to synchronous signals, since they are really traps, like SIGFPE
and SIGSEGV. If you want to use asynchronous signals in your threaded
program, have one thread wait on all signals, while all of the other
threads block all signals. Then, the thread which receives the signals
can accept them and process them in an orderly fashion.

The license for the GEF source/code is the LGPL for the shared libraries
and the GPL for the source and static library (.a). Please use it and
let me know how you are fairing!

By the way, see http://www.*-*-*.com/ for some good online papers on
Design by Contract and Exception-Handling.
Bruce W. Bigby
Do for others what you would want others to do for you.

Mon, 18 Mar 2002 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. General Exception-Handling Facility and Contract Programming for C Programmers

2. Design by Contract

3. FL-Several C++ OO Design Contracts!!!

4. Design by Contract

5. (ANN) Contract .NET Programmers Wanted

6. C Analyst/Programmer (Contract & Permanent)

7. Newsgroup for C Consultants/Contract Programmers

8. C Programmer needed for Contract Job

9. Contract Programmer wanted

10. US-CA-510 C/UNIX Programmers Needed - 11 month Contract (recruiter)

11. Contract "C" programmers wanted

12. Embedded C Programmer wanted - Contract position


Powered by phpBB® Forum Software