caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] CamlIDL: omitting struct fields
@ 2001-08-27  6:48 T Teemu E Kurppa
  2001-08-27  7:20 ` Dmitry Bely
  0 siblings, 1 reply; 3+ messages in thread
From: T Teemu E Kurppa @ 2001-08-27  6:48 UTC (permalink / raw)
  To: caml-list

Last weekend I started working on a hobby project, where I'll use Ocaml to
implement some parts of game AI for a game, which itself is written in
plain C. I'm using CamlIDL to help interfacing between C and Ocaml.

Unfortunately I encountered problems, when I omitted some struct fields
from IDL specification. According the chapter 6 of CamlIDL manual
(http://caml.inria.fr/camlidl/htmlman/main006.html), omitting irrelevant
struct fields should be possible.

However, a following example doesn't work the way I think it should work.
In the C struct, three int fields x,y,z are defined. In IDL definition,
I omit y.

Program prints
x=1, y=3, z=134648512
althought I think it should print (of course y can be any number)
x=1, y=4911232, z=3

Have I misunderstood something ?


- c_impl.c: ---------------------------

#include <stdio.h>

struct bar {
  int x;
  int y;
  int z;
};

void f (struct bar* pbar) {
  printf ("x=%d, y=%d, z=%d\n", pbar->x, pbar->y, pbar->z);
  return;
}



- c_idl.idl: ------------------------------
struct bar {
  int x;
  //int y;
  int z;
};

void f ([in,ref] struct bar* pbar);



- idl_test.ml: ---------------------------
open C_idl

let main () =
  let bar = {x = 1;
           (*y = 2;*)
             z = 3} in
    f(bar)

let _ = main ()


-- 
Teemu Kurppa
Teemu.Kurppa@Helsinki.fi

-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] CamlIDL: omitting struct fields
  2001-08-27  6:48 [Caml-list] CamlIDL: omitting struct fields T Teemu E Kurppa
@ 2001-08-27  7:20 ` Dmitry Bely
  2001-08-27 10:49   ` T Teemu E Kurppa
  0 siblings, 1 reply; 3+ messages in thread
From: Dmitry Bely @ 2001-08-27  7:20 UTC (permalink / raw)
  To: caml-list

T Teemu E Kurppa <ttkurppa@cs.Helsinki.FI> writes:

> Last weekend I started working on a hobby project, where I'll use Ocaml to
> implement some parts of game AI for a game, which itself is written in
> plain C. I'm using CamlIDL to help interfacing between C and Ocaml.
> 
> Unfortunately I encountered problems, when I omitted some struct fields
> from IDL specification. According the chapter 6 of CamlIDL manual
> (http://caml.inria.fr/camlidl/htmlman/main006.html), omitting irrelevant
> struct fields should be possible.
> 
> However, a following example doesn't work the way I think it should work.
> In the C struct, three int fields x,y,z are defined. In IDL definition,
> I omit y.
> 
> Program prints
> x=1, y=3, z=134648512
> althought I think it should print (of course y can be any number)
> x=1, y=4911232, z=3
> 
> Have I misunderstood something ?

Maybe :-) If you really need the trick with fields omitting (BTW, why?),
you should manually include the header file with "bar" definition into the
camlidl-generated c_idl.c, so it will use the correct memory
layout. Camlidl manual says that very clear.

> - c_impl.c: ---------------------------
> 
> #include <stdio.h>
> 
> struct bar {
>   int x;
>   int y;
>   int z;
> };
> 
> void f (struct bar* pbar) {
>   printf ("x=%d, y=%d, z=%d\n", pbar->x, pbar->y, pbar->z);
>   return;
> }
> 
> 
> 
> - c_idl.idl: ------------------------------
> struct bar {
>   int x;
>   //int y;
>   int z;
> };
> 
> void f ([in,ref] struct bar* pbar);
> 
> 
> 
> - idl_test.ml: ---------------------------
> open C_idl
> 
> let main () =
>   let bar = {x = 1;
>            (*y = 2;*)
>              z = 3} in
>     f(bar)
> 
> let _ = main ()

Hope to hear from you soon,
Dmitry


-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] CamlIDL: omitting struct fields
  2001-08-27  7:20 ` Dmitry Bely
@ 2001-08-27 10:49   ` T Teemu E Kurppa
  0 siblings, 0 replies; 3+ messages in thread
From: T Teemu E Kurppa @ 2001-08-27 10:49 UTC (permalink / raw)
  To: caml-list

On 27 Aug 2001, Dmitry Bely wrote:

> T Teemu E Kurppa <ttkurppa@cs.Helsinki.FI> writes:
>
> > Unfortunately I encountered problems, when I omitted some struct fields
> > from IDL specification. According the chapter 6 of CamlIDL manual
> > (http://caml.inria.fr/camlidl/htmlman/main006.html), omitting
> > irrelevant struct fields should be possible.
< ... skipping ... >
> > Have I misunderstood something ?
>
> Maybe :-) If you really need the trick with fields omitting (BTW, why?),

The C-part of the implementation has many C-structs with information
relevant for the AI,  but unfortunately these structs also contain some
GUI-specific fields. Design flaw obviously (Hey, I haven't done it ! :)).

So I thought it would be cleaner to omit these fields with CamlIDL.

> you should manually include the header file with "bar" definition into
> the camlidl-generated c_idl.c, so it will use the correct memory
> layout. Camlidl manual says that very clear.

Okay, I think I understand the problem now. IMHO the manual didn't state
this very clearly in Chapter 6, but on the other hand it would be better
to read the whole manual before whining ;)

Anyway, I noticed that it's possible to avoid _manual_ modification of
camlidl-generated file with quote-statement and -no-include switch.
Below is a working example for those who have stumbled on same problem.
Add -no-include switch to camlidl command.

> Hope to hear from you soon,
> Dmitry

I'll report, if I get something interesting done. And thanks for the
help !

Teemu


- c_idl.idl --------------------------
quote( h, "#include \"c_impl.h\"\n")

struct bar {
  int x;
  //int y;
  int z;
};

void f ([in,ref] struct bar* pbar);



- c_impl.h ---------------------------
#ifndef C_IMPL_H
#define C_IMPL_H

struct bar {
  int x;
  int y;
  int z;
};

#endif



- c_impl.c ---------------------------
#include <stdio.h>
#include "c_impl.h"

void f (struct bar* pbar) {
  printf ("x=%d, y=%d, z=%d\n", pbar->x, pbar->y, pbar->z);
  return;
}


- idl_test.ml ------------------------
open C_idl

let main () =
  let bar = {x = 1;
	   (*y = 2;*)
	     z = 3} in
    f(bar)

let _ = main ()


Teemu Kurppa
Teemu.Kurppa@Helsinki.fi


-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-08-27 10:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-27  6:48 [Caml-list] CamlIDL: omitting struct fields T Teemu E Kurppa
2001-08-27  7:20 ` Dmitry Bely
2001-08-27 10:49   ` T Teemu E Kurppa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).