At this point, you're effectively fighting the compiler. You could try an enum since enum values aren't directly convertible to integers without an explicit typecast -- maybe the compiler will get the hint.<br>Do you really need to have the exact same name? Is it completely infeasible to have a function like int get_nif(...) instead of just "get" as an overload? (aka: the easy solution)<br>
<br>Patrick<br><br><br><div class="gmail_quote">On Sun, Mar 18, 2012 at 8:07 PM, Daniel Goertzen <span dir="ltr"><<a href="mailto:daniel.goertzen@gmail.com">daniel.goertzen@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I am working on a c++ nif and have an overloaded function that takes a number of different types including integers and ERL_NIF_TERMs. The problem is that ERL_NIF_TERM really just an integer and collides with my integer functions, for example:<div>
<br></div><div>int get(std::string var) {...}</div><div>int get(unsigned long var) {...}</div><div>int get(ERL_NIF_TERM var) {...} //compile error because ERL_NIF_TERM is really an unsigned long.</div><div><br></div><div>
It would be great it ERL_NIF_TERM was a unique type so it could be used in this situation.</div><div><br></div><div>My first attempt to solve this involved creating wrappers for each NIF API function. The wrapper used a new unique type instead of ERL_NIF_TERM, and did type casting as needed. It was a type punning bloodbath. This was complex and unsatisfactory.</div>
<div><br></div><div>My second attempt was to hack erl_nif.h to change the definition of ERL_NIF_TERM to a struct containing an int, and this worked great. But this is not very portable due to the custom erl_nif.h. Also, I don't know enough about linkers to know for sure if this is permitted.</div>
<div><br></div><div><br></div><div>Has this problem come up before?</div><div><br></div><div>Is there some easy alternative that I am missing?</div><div><br></div><div>Should I submit a patch for the erl_nif.h hack? (It is conditionally compiled, by default nothing changes)</div>
<div><br></div><div><br></div><div>Thanks,</div><div>Dan.</div>
<br>_______________________________________________<br>
erlang-bugs mailing list<br>
<a href="mailto:erlang-bugs@erlang.org">erlang-bugs@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-bugs" target="_blank">http://erlang.org/mailman/listinfo/erlang-bugs</a><br>
<br></blockquote></div><br>