Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Data_custom_val(v)
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Xavier Leroy <Xavier.Leroy@i...>
Subject: Re: [Caml-list] Data_custom_val(v)
> I forgot to mention that Data_custom_val(v) doesn't allow for
> assignments in C++, instead I have to use
> 
>     value blk = alloc_custom(...);
>     *(void **)&(Field(blk, 1)) = (void *)some_data;

Don't do that, because someday the data part of the custom block may
not be at offset 1.

What is wrong with

     value blk = alloc_custom(...);
     mytype * mydata = (mytype *) Data_custom_val(v);
     *mydata = <initial value>;

or, more concisely,
     *((mytype *) Data_custom_val(v)) = <initial value>;

Is it that evil C++ that don't let you do that?

- Xavier Leroy
-------------------
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