Date: Wed, 31 Oct 2007 03:11:36 +0200 From: Giorgos Keramidas <keramida@ceid.upatras.gr> To: Bakul Shah <bakul@bitblocks.com> Cc: Poul-Henning Kamp <phk@phk.freebsd.dk>, Alfred Perlstein <alfred@freebsd.org>, Garance A Drosehn <gad@freebsd.org>, freebsd-arch@freebsd.org Subject: Re: C++ in the kernel Message-ID: <20071031011136.GA33331@kobe.laptop> In-Reply-To: <20071030163613.E70665B30@mail.bitblocks.com> References: <20071030055840.GS33488@elvis.mu.org> <20071030163613.E70665B30@mail.bitblocks.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On 2007-10-30 09:36, Bakul Shah <bakul@bitblocks.com> wrote: > The structured macro paper referenced on the K wiki page also > seems rather interesting. A powerful macro facility needs to > be well integrated with the language (much like Lisp or > Scheme's macros) so that you can write for instance > > critical_section(lock) { > ... > bar: > ... > if (cond1) break; > ... > if (cond2) goto foo; > ... > if (cond3) goto bar; > ... > if (cond4) return; // from enclosing function > ... > } > ... > foo: > > and have it transform to vanilla C code that does proper > unlocking on any exit. To a first approximation I think of > them as compile time "functions" that take identifiers and code > as arguments and return code. That sounds interesting indeed. Even userlevel code can benefit greatly from a structured macro enhancement to plain, vanilla C. I've been reading a lot about macros in both C and Lisp Usenet groups, but I am not sure how feasible it would be to have in a C-like language the deeply integrated macros like: (exception-handling-code (critical-section (lock) ...)) without an equivalently advanced mechanism for handling exceptions in the case the macros fail. At least, not in a way that doesn't make the C-like language sufficiently unportable to be tricky to implement & use. For example, in the critical_section() macro above, 'break' is a quite 'plain' C feature, but it should suddenly grow enough knowledge about the encapsulating macro to DTRT. The 'return' keyword is similar. Anything that is related to scope of the lock object too, and we are already in our way to design something that is superficialy similar to C but only in a very basic level of syntax :/ > Coming up with something that is semantically well defined & > integrates well with C can not be easy. All budding feature > designers ought to read Tony Hoare's "Hints on programming > language design". Still relevant after 33 years. Search for > cb-p193-hoare.pdf. Right on the spot, indeed.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20071031011136.GA33331>