caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: [Caml-list] void/unit in C calls
@ 2004-02-20 20:16 Lars Nilsson
  2004-02-20 20:36 ` [Caml-list] " Jed Davis
  0 siblings, 1 reply; 2+ messages in thread
From: Lars Nilsson @ 2004-02-20 20:16 UTC (permalink / raw)
  To: caml-list

>It makes a difference: you should always return Val_unit from
>unit-functions implemented in C. Otherwise you might find obscure
>things like:
>
>   foo () <> ()
>
>Or worse... - somebody reported to me that he sometimes saw programs
>crash, though it isn't certain that this was the cause.

Does this indicate an error in the O'Caml manual, section 18.5.1, where

  void foo(value v1, value v2, value v3)
  {
    CAMLparam3(v1, v2, v3);

    CAMLreturn0;
  }

is used, in addition to a paragraph preceeding it in the same section saying 
"If your C function is a procedure you must insert CAMLreturn0 at the end"? 
In fact, CAMLreturn0 existing at all seems to imply the fact that 
unit-returning functions (from O'Caml's point of view) can be void in the C 
implementation.

Lars

_________________________________________________________________
Say “good-bye” to spam, viruses and pop-ups with MSN Premium -- free trial 
offer! http://click.atdmt.com/AVE/go/onm00200359ave/direct/01/

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* [Caml-list] Re: void/unit in C calls
  2004-02-20 20:16 [Caml-list] void/unit in C calls Lars Nilsson
@ 2004-02-20 20:36 ` Jed Davis
  0 siblings, 0 replies; 2+ messages in thread
From: Jed Davis @ 2004-02-20 20:36 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 1238 bytes --]

"Lars Nilsson" <lazarus13@hotmail.com> writes:

> Does this indicate an error in the O'Caml manual, section 18.5.1, where
>
>   void foo(value v1, value v2, value v3)
>   {
>     CAMLparam3(v1, v2, v3);
>
>     CAMLreturn0;
>   }
>
> is used, in addition to a paragraph preceeding it in the same section
> saying "If your C function is a procedure you must insert CAMLreturn0
> at the end"? In fact, CAMLreturn0 existing at all seems to imply the
> fact that unit-returning functions (from O'Caml's point of view) can
> be void in the C implementation.

It doesn't say that foo() is meant to be the implementation of an
external in and of itself; in fact, the absence of a CAMLprim
indicates that it's not meant to be one.  It's just that any function
that might set off a GC needs to declare its "value"s so they can be
updated if the referenced blocks are moved, and thus needs a matching
CAMLreturn.


-- 
[Jed Davis]              A098 903E 9B9A DEF4 168F  AA09 BF07 807E F336 59F9
 <jdev@panix.com>                                               0xF33659F9
  "But life wasn't yes-no, on-off.  Life was shades of gray, and rainbows
   not in the order of the spectrum." -- L. E. Modesitt, Jr., _Adiamante_

[-- Attachment #2: Type: application/pgp-signature, Size: 185 bytes --]

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

end of thread, other threads:[~2004-02-20 20:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-20 20:16 [Caml-list] void/unit in C calls Lars Nilsson
2004-02-20 20:36 ` [Caml-list] " Jed Davis

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