[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Including C struct definitions
From: |
felix winkelmann |
Subject: |
Re: [Chicken-users] Including C struct definitions |
Date: |
Mon, 20 Dec 2004 11:48:22 +0100 |
On 20 Dec 2004 11:41:10 +0100, Nicolas Pelletier
<address@hidden> wrote:
> Hello,
>
> I am using Chicken 1.72 and would like to embed C structs in Scheme
> code. Some fields in these structures are themselves structued types,
> and csc gives an error on such structures. Here is what my code looks
> like:
>
> my_structs.scm:
> #>!
> #include "my_structs.h"
> <#
>
> my_structs.h:
> typedef struct
> {
> unsigned char a;
> unsigned char b;
> } a_t;
>
> typedef struct
> {
> a_t c;
> unsigned long int d;
> } b_t;
>
> csc gives the following error:
> csc my_struct.scm -output-file my_struct.c
> Error: invalid type specifier: (struct (scope (unsigned char (id "a"))
> (unsigned char (id "b"))))
> *** Shell command terminated with exit status 1:
> /home/nicolasp/SunOS/chicken/bin/chicken struct.scm -output-file struct.c
> -quiet -output-file struct.c
>
> I tried the following trick without success:
> struct a_s
> {
> unsigned char a;
> unsigned char b;
> };
> typedef struct a_s a_t;
>
> struct b_s
> {
> struct a_s c;
> unsigned long int d;
> };
> typedef struct b_s b_t;
>
> This one chokes on the definition of the field called d.
>
> Is there a way to make this kind of structured types work ?
>
the easy ffi parser doesn't handle "long int", just use "long" in
this case. Also, embedded structs are not handled. You would need
to change the definition of "c" to be a pointer instead of a
struct.
(I will try to extend the FFI to handle these cases, though)
cheers,
felix