[erlang-questions] erl_nif interface

Sverker Eriksson <>
Tue Mar 30 17:25:18 CEST 2010

Looks ok in case you are running R13B03. If you are running R13B04 then 
the NIFs should look like this with argc and argv 

static ERL_NIF_TERM increase(ErlNifEnv* env, int argc, const 
ERL_NIF_TERM argv[]) {
int i;
enif_get_int(env, argv[0], &i);
PrivData* data = (PrivData*) enif_get_data(env);
return enif_make_int(env, i);

A good practice is to always check the return value of enif_get_int and 
friends. I think that's what's happening in your case; enif_get_int 
fails and you return an integer term with whatever value that 'i' 
happens to get by default.

/Sverker, Erlang/OTP Ericsson

William v Doorn wrote:
> Hello all,
> I'm pretty new to Erlang and decided to try out the erl_nif interface. I
> tried to make a simple counter, but I can't get it to work. It seems to go
> wrong at enif_make_int, where it seems to return the memory address instead
> of the integer itself.
> I've included these things in the paste:
> - C code using erl_nif
> - Erlang module
> - Interpreter session
> http://gist.github.com/348161
> Thanks,
> William van Doorn

More information about the erlang-questions mailing list