Hi Collin,

> I'm curious, though, what is the benefit of compiling a C program, like
> clisp, with a C++ compiler?

The benefit is that you can attach all kinds of behaviours to your objects.

A simple use-case might be to add logging/tracing to specific objects.

In GNU clisp, which has a compacting garbage collection, the use-case is
to detect situations where the garbage collection could see invalid pointers
and then crash. Example:

  object x = STACK[-3];        /* x is not among the GC roots */
  object y = allocate_cons (); /* may trigger GC */
  Cdr(y) = x;                  /* storing an invalid object in the heap! */

Corrected example:

  object x = STACK[-3];        /* take a value from the stack */
  pushSTACK (x);               /* and duplicate it on the stack */
  object y = allocate_cons (); /* may trigger GC */
  Cdr(y) = popSTACK ();

We don't have a static analyzer for this kind of (frequent) mistakes.
Defining 'object' as a C++ class detects these mistakes at runtime.

Bruno




Reply via email to