questions about union.cl example
John DeSoi <jdesoi-sEd41pF3X/[email protected]> Sun, 8 Sep 2002 20:23:36 -0400
| Newsgroups | gmane.lisp.uffi.devel |
|---|---|
| Message-ID | <p05111b00b9a18827752a@[192.168.1.6]> |
Is it appropriate to assign the 'uint slot (a short int, right?) with
a long integer value? It seems that it should be an error to do that.
I could not get it to work until I changed the types to long and
unsigned-long.
The number computed for sparc (and powerpc) is 1094861823. My
inspector says this is a 31 bit value (unlike the non-sparc number
which is a 32 bit value):
#b1000001010000100100001111111111
#x414243FF
So this is what I get with MCL and OpenMCL:
? (run-union-1)
Should be #A: #\A
Should be negative number: 1094861823
Should be positive number: 1094861823
This seems correct since 1094861823 is really a 31 bit value. Am I
missing something? What is the correct test value?
Thanks,
John DeSoi, Ph.D.
=====
(uffi:def-union tunion1
(char :char)
(int :int)
(uint :unsigned-int)
(sf :float)
(df :double))
(defun run-union-1 ()
(let ((u (uffi:allocate-foreign-object 'tunion1)))
(setf (uffi:get-slot-value u 'tunion1 'uint)
#-(or sparc powerpc)
(+ (* 1 (char-code #\A))
(* 256 (char-code #\B))
(* 65536 (char-code #\C))
(* 16777216 255))
#+(or sparc sparc-v9 powerpc)
(+ (* 16777216 (char-code #\A))
(* 65536 (char-code #\B))
(* 256 (char-code #\C))
(* 1 255)))
(format *standard-output* "~&Should be #\A: ~S"
(uffi:ensure-char-character
(uffi:get-slot-value u 'tunion1 'char)))
(format *standard-output* "~&Should be negative number: ~D"
(uffi:get-slot-value u 'tunion1 'int))
(format *standard-output* "~&Should be positive number: ~D"
(uffi:get-slot-value u 'tunion1 'uint))
(uffi:free-foreign-object u))
(values))