Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] camlidl - character arrays?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Dmitry Bely <dbely@m...>
Subject: Re: [Caml-list] camlidl - character arrays?
Brian Naylor <> writes:

> I am trying to use CamlIDL for a C function like the following:
>     int foo (unsigned char [16]);
> If I write my CamlIDL file like this:
>     int foo ([in,string] unsigned char s [16]);
> The code does a check like this:
>     if (string_length(_v_s) >= 16) invalid argument("foo");
> The problem is that this is NOT a null-terminated string - it is exactly 16
> bytes of data.

You have two options here:

1. Don't use "string" attribute and pass OCaml character array (not string)
to your function or
2. Declare it as
     int foo ([string] unsigned char s[17]);
As C arrays are passed by the pointer, your C function will never know that
the trailing '\0' is there.

Dmitry Bely

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: