caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] void/unit in C calls
@ 2004-02-20 19:26 Michael Furr
  2004-02-20 19:41 ` Shawn Wagner
  2004-02-20 19:50 ` Markus Mottl
  0 siblings, 2 replies; 4+ messages in thread
From: Michael Furr @ 2004-02-20 19:26 UTC (permalink / raw)
  To: caml-list


I realize this is somewhat of a pedantic question but, what is the proper
prototype for a C function which has a parameter of type unit?
ie:
 external foo : unit -> unit = "foo_c"

should foo_c be declared
 void foo_c(void);
or
 value foo_c(value);

Would it ever cause a problem on any architecture if one used the wrong
form?

thanks,
-Mike

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

* Re: [Caml-list] void/unit in C calls
  2004-02-20 19:26 [Caml-list] void/unit in C calls Michael Furr
@ 2004-02-20 19:41 ` Shawn Wagner
  2004-02-20 19:50 ` Markus Mottl
  1 sibling, 0 replies; 4+ messages in thread
From: Shawn Wagner @ 2004-02-20 19:41 UTC (permalink / raw)
  To: caml-list

On Fri, Feb 20, 2004 at 02:26:05PM -0500, Michael Furr wrote:
> 
> I realize this is somewhat of a pedantic question but, what is the proper
> prototype for a C function which has a parameter of type unit?
> ie:
>  external foo : unit -> unit = "foo_c"
> 
> should foo_c be declared
>  void foo_c(void);
> or
>  value foo_c(value);

This one.

> 
> Would it ever cause a problem on any architecture if one used the wrong
> form?

Yup. I've had problems with the bytecode runtime not liking C functions that
don't return anything when they should be returning a Val_unit.

-- 
Shawn Wagner
shawnw@speakeasy.org

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

* Re: [Caml-list] void/unit in C calls
  2004-02-20 19:26 [Caml-list] void/unit in C calls Michael Furr
  2004-02-20 19:41 ` Shawn Wagner
@ 2004-02-20 19:50 ` Markus Mottl
  1 sibling, 0 replies; 4+ messages in thread
From: Markus Mottl @ 2004-02-20 19:50 UTC (permalink / raw)
  To: Michael Furr; +Cc: caml-list

On Fri, 20 Feb 2004, Michael Furr wrote:
> I realize this is somewhat of a pedantic question but, what is the proper
> prototype for a C function which has a parameter of type unit?
> ie:
>  external foo : unit -> unit = "foo_c"
> 
> should foo_c be declared
>  void foo_c(void);
> or
>  value foo_c(value);
> 
> Would it ever cause a problem on any architecture if one used the wrong
> form?

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.

It shouldn't matter whether you pass void or value to C, I think, unless
you want to use the value - which is quite unlikely.

Regards,
Markus

-- 
Markus Mottl          http://www.oefai.at/~markus          markus@oefai.at

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

* Re: [Caml-list] void/unit in C calls
@ 2004-02-20 20:16 Lars Nilsson
  0 siblings, 0 replies; 4+ 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] 4+ messages in thread

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

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-20 19:26 [Caml-list] void/unit in C calls Michael Furr
2004-02-20 19:41 ` Shawn Wagner
2004-02-20 19:50 ` Markus Mottl
2004-02-20 20:16 Lars Nilsson

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