-
Notifications
You must be signed in to change notification settings - Fork 54
/
c_main_int.m
32 lines (25 loc) · 1.09 KB
/
c_main_int.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
% This module c_main_int defines a Mercury predicate c_main which acts as an
% interface to the C function c_main(), which is defined in c_main.c.
% This source file is hereby placed in the public domain. -fjh (the author).
:- module c_main_int.
:- interface.
:- import_module io.
% Since the c_main() function has side effects, we declare the corresponding
% Mercury predicate as one that takes an io.state pair. If we didn't do this,
% the Mercury compiler might optimize away calls to it!
:- pred c_main(io::di, io::uo) is det.
:- implementation.
% #include the header file containing the function prototype for c_main(),
% using a `pragma foreign_decl' declaration.
% Note that any double quotes or backslashes in the C code for the
% `#include' line must be escaped, since the C code is given as a Mercury
% string.
:- pragma foreign_decl("C", "#include \"c_main.h\"").
% Define the Mercury predicate c_main to call the C function c_main().
:- pragma foreign_proc("C",
c_main(IO0::di, IO::uo),
[promise_pure, will_not_call_mercury],
"
c_main();
IO = IO0;
").