This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: typedef void * SCM


On Thu, 17 Feb 2000, Han-Wen Nienhuys wrote:

> Hi guys,
> 
> today, I didn't feel like doing Real Work (tm), so I decided to take
> on one of my pet peeves: making the type checking for GUILE C-code a
> little more robust, by setting
> 
>        typedef void * SCM;
> 
> and doing appropriate casts everywhere.  I've changed lots of code
> that did bitdiddling. You can review the patch up on my homepage, at
> http://www.cs.uu.nl/~hanwen/software/guile-voidp.

May I tell you that this is _very_ great news to hear?  Thank you very
much for starting this important task!  However, some time ago there was 
some discussion about whether void* would be the appropriate type to
use.  Definitely, it is better than long (the current choice), but it
became clear during that discussion, that an unnamed struct would be the
best choice, because with a struct you can't by mistake do:

SCM some_scm_bool;
...
if (some_scm_bool) ...

Thus, the following suggestion was made (the names of the macros could
probably need some improvement :-), I just want to point out the idea):

#ifdef GUILE_BACKWARDS_COMPATIBILITY_MODE
    typedef long SCM;
    #define SCM_BITS(X) (X)
#else
#ifdef GUILE_COMPILE_TIME_DEBUG_MODE
    typedef union { long n; } SCM;
    #define SCM_BITS(X) ((X).n)
#else
    typedef void * SCM;
    #define SCM_BITS(X) ((long)(X))
#endif
#endif

This way you can compile everything as before, if compatibility mode is
defined.  Nevertheless you can incrementally change accesses to SCM values
to use the SCM_BITS macro.  Although it seems a little verbose to access
the contents of a SCM variable via SCM_BITS, you get the necessary casting
for free.  And finally, you can even do a very thorough type checking by
defining the compile time debug mode.  However, the results of this
compilation are best thrown away, since the current gcc will treat the SCM
struct not very efficiently.

The discussion thread was called 'compile time debug
mode'.  Unfortunately, there was no final statement by the maintainers
about whether this would make sense.  But since you have already put some
effort into finding the places where casting is required, it could be the
right time to decide about it.

BTW: I think especially SCM_BITS should be replaced by something else,
which can more easily be grepped.  Now you already get some entries with
SCM_BITS.  What about SCM_CONTENT, or SCM_EXTRACT, or I don't
know?  Native speakers?

Best regards
Dirk Herrmann


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]