From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id SAA13431 for caml-redistribution; Sat, 29 Aug 1998 18:46:56 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id LAA09680 for ; Thu, 27 Aug 1998 11:16:52 +0200 (MET DST) Received: from infbssys.ips.cs.tu-bs.de (infbssys.ips.cs.tu-bs.de [134.169.32.1]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id LAA03425 for ; Thu, 27 Aug 1998 11:16:50 +0200 (MET DST) Received: from infbsstq.ips.cs.tu-bs.de (lindig@infbsstq.ips.cs.tu-bs.de [134.169.32.78]) by infbssys.ips.cs.tu-bs.de (8.9.1/8.9.1) with ESMTP id LAA05207 for ; Thu, 27 Aug 1998 11:16:35 +0200 Date: Thu, 27 Aug 1998 11:16:34 +0200 Message-Id: <199808270916.LAA06931@infbsstq.ips.cs.tu-bs.de> From: Christian Lindig To: Caml Mailing List Subject: Passing `string option' values between OCaml and C Sender: weis After reading the manual, the mailing list archive, and some OCaml C sources I'm still not sure how to read and build constructed values in C. Two functions in the OCaml C source that receive optional values act quite differently: weak_set() in byterun/weak.c tests for value el != 1 to recognize the Some case: #define None_val 1 #define Some_tag 0 /* type 'a option = None | Some of 'a * val set : 'a t -> int -> 'a option -> unit */ value weak_set (value ar, value n, value el) /* ML */ { ... if (el != None_val){ Modify (&Field (ar, offset), Field (el, 0)); } ... } win_create_process() in otherlibs/win32unix/createprocess.c on the other hand tests optional value env != Val_int(0) to do this: /* * win_create_process : string -> string -> string option -> * file_descr -> file_descr -> file_descr -> int */ value win_create_process_native(value cmd, value cmdline, value env, value fd1, value fd2, value fd3) { ... if (env != Val_int(0)) { envp = String_val(Field(env, 0)); } else { envp = NULL; } ... } Could someone explain the general way how to read and build constructed values in C using optional values as an example? Starting with some #defines derived from the OCaml type definition to nail down the tags seems a good starting point to me. Christian ------------------------------------------------------------------------------ Christian Lindig http: www.cs.tu-bs.de/softech/people/lindig mail: lindig@ips.cs.tu-bs.de phone: +49 531 391 7465 fax: +49 531 391 8140