[plt-scheme] two tricky types

From: Eli Barzilay (eli at barzilay.org)
Date: Mon Sep 12 08:46:12 EDT 2005

On Sep 12, Pupeno wrote:
> Hello,
> I am writting some FFIs on PTL Scheme 299.400 and I encountered two tricky 
> types on MySQL:
> 
> One is:
> 	typedef char my_bool;
> which is similar to foreing's bool, but it uses char instead of bool (it seems 
> the mysql guys want to save memory), so, I implemented it this way:
>   (define _my_bool (make-ctype _byte
>                               (lambda (x)
>                                 (if x 1 0))
>                               (lambda (x)
>                                 (if (= x 0) #f #t))))
> Is it all-rigth?

Yes, except that I'd write:

  (define _my_bool
    (make-ctype _byte
                (lambda (x) (if x 1 0))
                (lambda (x) (not (eq? 0 x)))))


> And the other one is a bit more tricky:
> 
> #if defined(NO_CLIENT_LONG_LONG)
> typedef unsigned long my_ulonglong;
> #elif defined (__WIN__)
> typedef unsigned __int64 my_ulonglong;
> #else
> typedef unsigned long long my_ulonglong;
> #endif

Seems like these are all attempts to get to a 64-bit integer, with
that NO_CLIENT_LONG_LONG being an exception that simply uses longs.


> I do not care about Windows but I am not sure where
> NO_CLIENT_LONG_LONG comes from, so I did:
> (define _my_ulongulong (make-ctype _ulong #f #f))
> any ideas if that is ok ?

This is effectively the same as

  (define _my_ulongulong _ulong)

which is the same as using _ulong.  My guess is that they really want
a 64 bit integer, so it might be better to use _uint64.
-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


Posted on the users mailing list.