Skip to search.
ocaml_beginners · Ocaml Beginners

Group Information

? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Messages

  Messages Help
Advanced
Interfacing Ocaml with global C variables ?   Message List  
Reply Message #10055 of 13557 |
Hi List !

I'm new to try mixing OCaml and C.

Please how to read/write a C global variable from OCaml ?

The normal external interfacing way we can use to call C functions doesn't work
- getting the error :
"External identifiers must be functions".

The way to bypass this could it be to declare two functions :
- one to read from the C variable and
- the other to write into it ?

But maybe is it far more simple or, the opposite way, does this raises some
problem with the GC ?

Thanks for your help,

Fabrice




Sat Aug 30, 2008 6:43 am

fabrice.marc...
Offline Offline
Send Email Send Email

Message #10055 of 13557 |
Expand Messages Author Sort by Date

Hi List ! I'm new to try mixing OCaml and C. Please how to read/write a C global variable from OCaml ? The normal external interfacing way we can use to call C...
Fabrice Marchant
fabrice.marc... Offline Send Email
Aug 30, 2008
8:39 am

... The big question is what is the C global? An int? A string? An array? Structure? etc. OCaml cannot just directly access C globals. At best you'd need...
Richard Jones
rwmjones Offline Send Email
Aug 30, 2008
9:33 am

... maybe another way than what richard pointed, if you really wish to share a variable between OCaml and C whithout calling a function at each access to the...
Florent Monnier
fmonnier@... Send Email
Aug 30, 2008
2:01 pm

Thanks a lot Florent for your interesting alternative answers ! However, there are some points I'm not sure to understand : On Sat, 30 Aug 2008 16:04:42 +0200 ...
Fabrice Marchant
fabrice.marc... Offline Send Email
Aug 30, 2008
5:44 pm

Thanks a lot for your answer that covers interesting and unexpected points ! On Sat, 30 Aug 2008 10:33:50 +0100 ... Returning only the address of the C global...
Fabrice Marchant
fabrice.marc... Offline Send Email
Aug 30, 2008
4:03 pm

... /* Variable shared between C and OCaml. */ #include <caml/mlvalues.h> /* On the OCaml side, this will be made to look like a structure * containing a...
Richard Jones
rwmjones Offline Send Email
Aug 30, 2008
7:56 pm

Many thanks Rich for this example I needed to understand ! On Sat, 30 Aug 2008 20:56:43 +0100 ... It sounds theoretical because all runs fine. But maybe does...
Fabrice Marchant
fabrice.marc... Offline Send Email
Aug 30, 2008
10:13 pm

... It's possible, although in this case it seems unlikely. 'ocamlopt' compiles very literally, so if you ask it to access a structure member, then it...
Richard Jones
rwmjones Offline Send Email
Aug 31, 2008
7:09 am
Advanced

Copyright © 2010 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines NEW - Help