[m-users.] FFI C Include files not appearing

Peter Wang novalazy at gmail.com
Tue Jun 25 20:42:13 AEST 2019


On Tue, 25 Jun 2019 11:03:53 +0100, emacstheviking <objitsu at gmail.com> wrote:
> Hi,
> I have these two lines of code...
> 
> :- pragma foreign_decl("C", "#include <SDL/SDL.h>").
> :- pragma foreign_decl("C", "#include <SDL/SDL_version.h>").
> 
> at the top of my module in the implementation section and this code too:
> :- func sdl_up = int.
> :- pragma foreign_proc("C",
>                        sdl_up = (Result::out),
>                        [ will_not_call_mercury
>                        , not_thread_safe
>                        , promise_pure
>                        ],
>                        "Result = SDL_Init(SDL_INIT_EVERYTHING);").
> 

Hi,

SDL_Init() is impure, so wrapping it up in pure function is incorrect.
Rather, you should wrap it in a predicate that takes the I/O state:

    :- pred sdl_up(int::out, io::di, io::uo) is det.

    :- pragma foreign_proc("C",
        sdl_up(Result::out, _IO0::di, _IO::uo),
        [will_not_call_mercury, promise_pure],
    "
        Result = SDL_Init(SDL_INIT_EVERYTHING);
    ").

Peter


More information about the users mailing list