tinycc-devel
[Top][All Lists]
Advanced

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

Re: [Tinycc-devel] TinyC++


From: Sam Watkins
Subject: Re: [Tinycc-devel] TinyC++
Date: Fri, 19 Nov 2010 12:18:26 +1100
User-agent: Mutt/1.5.18 (2008-05-17)

On Tue, Nov 16, 2010 at 10:56:04PM -0600, Jared Maddox wrote:
> In short, if you want to provide support for C++ features to TinyCC
> (whether through a preprocessor, flags, or a separate program), please
> do it via templates and a variant of setjmp()/longjmp() that supports
> destructor registration, not through classes.

Good ideas.  I think the templates functionality can best be done with a
preprocessor, and the enhanced longjmp with a library function.

I wrote a library which includes richer error-handling functions, and wrapper
functions e.g. Open() for open().  These wrappers call 'error()' when something
goes wrong.  I can configure my 'error' function to do different things,
e.g. print the message and exit(1), call longjmp, or just continue as if
nothing happened!

Using wrapper functions saves the need to type a lot of:

if (open(..) < 0) {
        handle_the_error;
        handle_the_error_some_more;
        ...
}

It makes the source code much more readable, and the object code is much
smaller too because there is less repetitious error checking.

I got this basic idea to write wrappers from one of W. Richard Stevens' books,
and it's also mentioned in 'The Practise of Programming' (Kernighan & Pike).
It really simplifies my code a lot.  I'm surprised not many people do it.


Sam



reply via email to

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