chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] How to deal with bit sets in chicken?


From: Kon Lovett
Subject: Re: [Chicken-users] How to deal with bit sets in chicken?
Date: Mon, 1 Jun 2009 21:46:52 -0700


On May 30, 2009, at 10:36 AM, Anthony Carrico wrote:

For example, according epoll_ctl(2) on the Linux AMD64 platform, the
following are __uint32_t.

(foreign-declare "#include <sys/epoll.h>\n")
(define-foreign-variable _EPOLLET unsigned-integer32 "EPOLLET")
(define EPOLLET _EPOLLET)
(define-foreign-variable _EPOLLONESHOT unsigned-integer32 "EPOLLONESHOT")
(define EPOLLONESHOT _EPOLLONESHOT)

#;2> EPOLLET
1.84467440715621e+19
#;3> EPOLLONESHOT
1073741824
#;4>


Here I declare them as int:

(define-foreign-variable _EPOLLET int "EPOLLET")
(define EPOLLET _EPOLLET)
(define-foreign-variable _EPOLLONESHOT int "EPOLLONESHOT")
(define EPOLLONESHOT _EPOLLONESHOT)

#;8> EPOLLET
-2147483648
#;9> EPOLLONESHOT
1073741824
#;10>

It seems like I can only get fixnums or flonums, is there a way to deal
with genuine 32-bit integers? What is the best way to declare

-2147483648 is the 2's complement of 2147483648 is 18446744071562100000 (1.84467440715621e+19) & 18446744071562100000 is 0xFFFFFFFF80007D20.

So your bits are persevered ... at least on 64-bit hardware. I suggest using 'unsigned-integer32' as the argument & return type when you know for sure that ALL 32 bits are significant so that the interface is compliant w/ 32-bit hardware. The flonum representation will be properly converted.

With Chicken (& other "high level" programming notations) "type" is not always synonymous w/ "representation".

Chicken will always treat a flonum w/o a fraction as an integer.
Ex: (integer? 1.84467440715621e+19) ;=> #t

 and
manipulate these in Chicken?

Depends on what you mean by "manipulate". If you plan on using the 'library' unit "bitwise-" operations on 32-bit hardware then there is a problem with the above magnitude. If all you need is I/O conversion w/ C library routines then the above advise is good. Otherwise we need to talk.

(See the unreleased Chicken 4 "err5rs-arithmetic-bitwise" module for a more generic set of operations that can deal with "real" machine words on 32 & 64 bit machines.)



Thank you.

--
Anthony Carrico

_______________________________________________
Chicken-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/chicken-users

Best Wishes,
Kon






reply via email to

[Prev in Thread] Current Thread [Next in Thread]