Version française
Home     About     Download     Resources     Contact us    
Browse thread
Help interfacing with C
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Nathaniel Gray <n8gray@g...>
Subject: Re: [Caml-list] Help interfacing with C
On 8/16/06, malc <malc@pulsesoft.com> wrote:
> On Wed, 16 Aug 2006, Nathaniel Gray wrote:
>
> > Hi folks,
> >
> > I'm having a heck of a time figuring out why this code *doesn't* work:
> >
> > /* fdlist is a list of (file_descr * 'a) pairs.  Filter by FD_ISSET */
> > static value fdset_to_fdlist2(value fdlist, fd_set *fdset)
> > {
> > value l, p, newres;
> > value res = Val_int(0);
> >
> > Begin_roots4(l, p, res, newres);  /* I know, this is aggressive */
> >   for (l = fdlist; l != Val_int(0); l = Field(l, 1)) {
> >     p = Field(l, 0);
> >     int fd = Int_val(Field(p, 0));
>
> This here (expanded) does Int_val (Field (Field (l, 0), 0))
>
> <snip>
>
> >     int fd = Int_val(Field(l, 0));
>
> <snip>
>
> I think the difference is self-evident.

Indeed, it's the entire point of the exercise.  In the first version l
is a list of (fd, 'a) pairs, in the second it's a list of fds.

Cheers,
-n8

-- 
>>>-- Nathaniel Gray -- Caltech Computer Science ------>
>>>-- Mojave Project -- http://mojave.cs.caltech.edu -->