C++ in the kernel

Giorgos Keramidas keramida at ceid.upatras.gr
Tue Oct 30 18:27:35 PDT 2007


On 2007-10-30 09:36, Bakul Shah <bakul at 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.



More information about the freebsd-arch mailing list