English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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: 2001-07-20 (14:01)
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