Files
mercury/tests/hard_coded/c_write_string.m
Julien Fischer 1c8eece402 Avoid warnings from MSVC in tests.
tests/hard_coded/backend_external.m:
tests/hard_coded/backend_external_pred.m:
tests/hard_coded/c_write_string.m:
tests/hard_coded/ee_dummy.m:
tests/hard_coded/pragma_c_code.m:
tests/hard_coded/pragma_foreign_export.m:
tests/hard_coded/target_mlobjs.m:
tests/hard_coded/type_tables.m:
tests/submodules/sm_exp_bug.m:
    Use don't-care variables to handle the I/O state in foreign procs.
    Assigning the I/O state at the end of the foreign_proc body results
    in spurious warnings about uninitialized variables from MSVC.
2023-07-22 23:24:54 +10:00

36 lines
886 B
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
:- module c_write_string.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
%---------------------------------------------------------------------------%
main(!IO) :-
c_write_string("Hello, world\n", !IO),
c_write_string("I am 8 today!\n", !IO),
c_write_string(X, !IO),
X = "fred\n".
:- pragma foreign_decl("C", "#include <stdio.h>").
:- pred c_write_string(string::in, io::di, io::uo) is det.
:- pragma foreign_proc("C",
c_write_string(Str::in, _IO0::di, _IO::uo),
[will_not_call_mercury, promise_pure],
"
fputs(Str, stdout);
").
c_write_string(Str, !IO) :-
% For the non-C backends.
io.write_string(Str, !IO).