Hi Steve<div><br></div><div>Thanks for you reply. Your help has answered my queries...</div><div><br></div><div>1.) I had a typo in ERL_NIF_INIT(), the module name parameter was pointing to a NIF function name and not the module name.</div><div><br></div><div>2.) I'm compiling with gcc on Debian. With my original compiler options "-Wall -W" the "-W" was generating the uninitialised structure field warning. Without the "-W" flag the warning is suppressed.</div><div><br></div><div>Many thanks for your help.</div><div><br></div><div>Kind regards</div><div><br></div><div>John<br><blockquote style="margin-right: 0px; margin-left:15px;">----Original message----<br>From : vinoski@ieee.org<br>Date : 02/09/2017 - 14:24 (BST)<br>To : jb_duffy@btinternet.com<br>Cc : erlang-questions@erlang.org<br>Subject : Re: [erlang-questions] NIF Query<br><br><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 1, 2017 at 7:13 PM, John Duffy <span dir="ltr"><<a href="mailto:jb_duffy@btinternet.com" target="_blank">jb_duffy@btinternet.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi<div><br></div><div>I'm trying to follow the Interoperability Tutorial Users Guide (Version 9.0) to create a module containing some simple NIFS. I have managed to do this, however I have needed to digress from the documentation as follows...</div><div><br></div><div>1.) if my module name doesn't match the filename in the call to erlang:load_nif("filename", 0) I get a compile error. This is not as per the example in the documentation, i.e. -module(complex6) & erlang:load_nif("complex6_nif, 0).</div></blockquote><div><br></div><div>Can you supply the details of the error you're getting? I followed the tutorial on my Mac and had no problems.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>2.) The appears to be a "flags" parameter missing in the {"foo", 1, foo_nif} structure in the documentation which generates a compile error...<br></div><div><br></div><div><font size="2"><span style="color:rgb(56,58,66);font-family:mono,Courier,monospace;background-color:rgb(250,250,250)">static ErlN</span><span class="gmail-m_-3759399636145656112hljs-keyword" style="font-family:mono,Courier,monospace;background-color:rgb(250,250,250);color:rgb(166,38,164)">if</span><span style="color:rgb(56,58,66);font-family:mono,Courier,monospace;background-color:rgb(250,250,250)">Func nif_funcs[] = {</span></font></div><pre style="font-family:mono,Courier,monospace;margin-top:0px;margin-bottom:0px;color:rgb(56,58,66);background-color:rgb(250,250,250)"><font size="2"> {<span class="gmail-m_-3759399636145656112hljs-string" style="color:rgb(80,161,79)">"foo"</span>, 1, foo_nif},
{<span class="gmail-m_-3759399636145656112hljs-string" style="color:rgb(80,161,79)">"bar"</span>, 1, bar_nif}
};
</font></pre><pre style="font-family:mono,Courier,monospace;margin-top:0px;margin-bottom:0px;color:rgb(56,58,66);background-color:rgb(250,250,250)"><font size="2"><br></font></pre><pre style="font-family:mono,Courier,monospace;margin-top:0px;margin-bottom:0px;color:rgb(56,58,66);background-color:rgb(250,250,250)"><font size="2">I have changed this to that below, which compiles, but what is the nature/value of "flags"?</font></pre><pre style="font-family:mono,Courier,monospace;margin-top:0px;margin-bottom:0px;color:rgb(56,58,66);font-size:11.2px;background-color:rgb(250,250,250)"><br></pre><div><div><font size="2"><span style="color:rgb(56,58,66);font-family:mono,Courier,monospace;background-color:rgb(250,250,250)">static ErlN</span><span class="gmail-m_-3759399636145656112hljs-keyword" style="font-family:mono,Courier,monospace;background-color:rgb(250,250,250);color:rgb(166,38,164)">if</span><span style="color:rgb(56,58,66);font-family:mono,Courier,monospace;background-color:rgb(250,250,250)">Func nif_funcs[] = {</span></font></div><pre style="font-family:mono,Courier,monospace;margin-top:0px;margin-bottom:0px;color:rgb(56,58,66);background-color:rgb(250,250,250)"><font size="2"> {<span class="gmail-m_-3759399636145656112hljs-string" style="color:rgb(80,161,79)">"foo"</span>, 1, foo_nif, 0},
{<span class="gmail-m_-3759399636145656112hljs-string" style="color:rgb(80,161,79)">"bar"</span>, 1, bar_nif, 0}
};
</font></pre></div><div><font size="2"><br></font></div><div><font size="2"><br></font></div><div><font size="2">I may be missing something, or the Tutorial may need updating?</font></div></blockquote><div><br></div><div>The flags field is described in <a href="http://erlang.org/doc/man/erl_nif.html">http://erlang.org/doc/man/erl_nif.html</a> -- it's currently used for values specific to dirty NIFs, which are also described on that page. For a regular NIF like the one in the tutorial, flags should be 0. Since the nif_funcs variable in the tutorial is defined as static, the C compiler is guaranteed to initialize flags to 0 because an initial value for it isn't specified.</div><div><br></div><div>Whether you get a problem from the flags field or not depends on your compiler and the options you pass to it. For example, copying and pasting the complex6_nif.c from the tutorial into a file and compiling it as follows on my Mac produced no errors or warnings:</div><div><br></div><div>clang -o complex6_nif.so complex.c complex6_nif.c -I/usr/local/lib/erlang/usr/include -bundle -flat_namespace -undefined suppress<br></div><div><br></div><div>But adding the -Wmissing-field-initializers option results in warnings:</div><div><br></div><div><div>complex6_nif.c:27:23: warning: missing field 'flags' initializer [-Wmissing-field-initializers]</div><div> {"foo", 1, foo_nif},</div><div> ^</div><div>complex6_nif.c:28:23: warning: missing field 'flags' initializer [-Wmissing-field-initializers]</div><div> {"bar", 1, bar_nif}</div><div> ^</div><div>2 warnings generated.</div></div><div><br></div><div>--steve</div></div></div></div>
<br></blockquote><br><p></p></div>