caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: matthieu.dubuget@laposte.net
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] CAMLreturn does not work for floats between 0 and 1 ?
Date: Sat, 17 Feb 2007 09:30:18 +0900 (JST)	[thread overview]
Message-ID: <20070217.093018.48529252.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <45D5C3AD.2000606@laposte.net>

From: Matthieu Dubuget <matthieu.dubuget@laposte.net>
> 
> I'm sure I'm doing something bad. But I can't find out where?
> 
> The problem is that when I CAMLreturn float : r with   0. < r < 1.,
> I get 0.00000000.
> 
> double f (int i){
>   CAMLparam0 ();
>   double r; 
>   static value *cr = NULL;
>   if (cr == NULL) cr = caml_named_value("f");
>   r = Double_val(caml_callback(*cr, Val_int(i)));
>   printf("f: r(%d)=%.5f\n", i, r);
>   CAMLreturn(r);
> }

As pointed by others, CAMLreturn can only be used for values of type
"value" (i.e. long int).
In this specific case, you need register no root with the GC, so there
is no point in using CAMLparam0/CAMLreturn.

If you need to register roots with the GC in such a function
(because you're calling two caml callbacks with an allocation in
between, for instance) then you must use different macros.
In 3.10, there is a new macro CAMLreturnT for this kind of
situations.
Before that, you can also use the older interface Begin_roots/End_roots.

   value v1 = 0, v2 = 0; // v1 and v2 must be initialized
   Begin_roots2(v1, v2);
   ... v1 and v2 are registered ...
   End_roots(); // pop v1 and v2
   return r;

Jacques Garrigue


      parent reply	other threads:[~2007-02-17  0:30 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-16 14:46 Matthieu Dubuget
2007-02-16 15:09 ` [Caml-list] " Daniel Bünzli
2007-02-16 16:20   ` Matthieu Dubuget
2007-02-16 17:02     ` Mathias Kende
2007-02-16 17:07     ` Daniel Bünzli
2007-02-16 19:19       ` Matthieu Dubuget
2007-02-16 22:28         ` Daniel Bünzli
2007-02-17  0:30 ` Jacques Garrigue [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070217.093018.48529252.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=matthieu.dubuget@laposte.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).