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: Casting to scm_bits_t


Dirk Herrmann <dirk@ida.ing.tu-bs.de> writes:

> in smob.h the data parameters are not cast automatically,
> thus the user has to perform that cast at every call to SCM_NEWSMOB.  But
> I'm not sure if this is really desirable?

FWIW, in my working copy I changed SCM_NEWSMOB{,2,3} to expect WORDs,
not OBJECTs for the data locations, and it seems to help wrt amount of
changes to get things to compile.  so I guess that's what people
expect.

> I'd suggest, to define SCM_PACK as follows (for strict typing, similarly
> for the other compilation modes):
> 
>     typedef union { struct { scm_bits_t n; } n; } SCM;
>     static SCM scm_pack(scm_bits_t b) { SCM s; s.n.n = b; return s; }
>     #define SCM_UNPACK(x) ((x).n.n)
>     #define SCM_PACK(x) (scm_pack ((scm_bits_t) (x)))
> 
> Reasons:
> * It's still not possible to confuse SCM and scm_bits_t
> * No need to add lots of (scm_bits_t) casts to the code.

strongly seconded (did it yesterday here, in fact.  I just can't stop, 
even if I know I'm duplicating your work ;( ).

> * Type safety can still be achieved.  How?  OK, example:
> 
>   #if defined (SCM_STRICT_TYPING)
>     static char * scm_i_char_ptr(char * x) { return x; }
>   #else
>     #define scm_i_char_ptr(x) (x)
>   #endif
>   #define SCM_SETCHARS(x, v)  (SCM_SET_CELL_WORD_1 ((x), scm_i_char_ptr (v)))
> 
> Then, we should get a nice compiler warning that tells us about any
> misuses of the macro SCM_SETCHARS.  In contrast, if we require the user to
> perform all of the casts in the code, like:
>   void * x;
>   SCM_SETCHARS ((scm_bits_t) x)
> there is no chance any more for a central testing
> place.  Consequence:  Casts in user code are bad, because any
> casting mistake in there can't be detected by clever macro tricks.

all good ideas, sorry for this <AOL> post.

-- 
All ITS machines now have hardware for a new machine instruction --
SETS
Set to Self.
Please update your programs.

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