caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Data_custom_val(v)
@ 2001-07-15  3:16 Alexander V. Voinov
  2001-07-20 14:00 ` Xavier Leroy
  0 siblings, 1 reply; 2+ messages in thread
From: Alexander V. Voinov @ 2001-07-15  3:16 UTC (permalink / raw)
  To: caml

Hi Developers,

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;

Alexander
-------------------
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] 2+ messages in thread

* Re: [Caml-list] Data_custom_val(v)
  2001-07-15  3:16 [Caml-list] Data_custom_val(v) Alexander V. Voinov
@ 2001-07-20 14:00 ` Xavier Leroy
  0 siblings, 0 replies; 2+ messages in thread
From: Xavier Leroy @ 2001-07-20 14:00 UTC (permalink / raw)
  To: Alexander V. Voinov; +Cc: caml

> 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


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

end of thread, other threads:[~2001-07-20 14:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-07-15  3:16 [Caml-list] Data_custom_val(v) Alexander V. Voinov
2001-07-20 14:00 ` Xavier Leroy

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).