<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div dir="ltr"></div><div dir="ltr">pow() must be giving you 9.9999999 (or something similar) instead of 10 which is rounded down to 9 by the int typecast. </div><div dir="ltr">This results in 3 * 9 + 2 = 29.</div><div dir="ltr">To solve this you can, for example, do a round() before the typecast or you can add 0.5 to the output of pow() before doing the typecast.</div><div dir="ltr"><br></div><div dir="ltr">Best!</div><div dir="ltr"><br></div><div dir="ltr">Edwin</div><div dir="ltr"><br>On 15 Aug 2022, at 08:31, Jaime Oliver <jaime.oliver2@gmail.com> wrote:<br><br></div><div dir="ltr"><div dir="ltr">Hi Chris, Brad, All,<div><br></div><div>I managed to trace the error to the function below. It reads a text file and copies its contents to a matrix. The file it's reading is always made of lines with the same number of elements like this below:</div><div><br></div><div>0 4 4 8 32<br>1 4 4 8 32<br>2 4 4 8 32<br></div><div>...</div><div><br></div><div>The specific error I'm getting right now is that it is reading that number 32 as 29. Again, this same code works fine in all other OSs I've tried.</div><div><br></div><div>I'm assuming the issue is in the pow() function and all the typecasting (int), (double) as Chris suggested?</div><div><br></div><div>As for compilation, I am using the latest pd_lib_builder as the makefile. </div><div><br></div><div>Thanks for your help!</div><div><br></div><div>best,</div><div><br></div><div>Jaime</div><div><br></div><div>code:</div><div><br></div><div><div style="color:rgb(0,0,0);font-family:Consolas,"Courier New",monospace;font-size:14px;line-height:19px;white-space:pre-wrap"><div><span style="color:rgb(0,0,255)">int</span> <span style="color:rgb(121,94,38)">readbarfile</span>(<span style="color:rgb(0,0,255)">int</span> <span style="color:rgb(0,16,128)">a</span><span style="color:rgb(0,0,255)">[]</span>[<span style="color:rgb(9,134,88)">8</span>], <span style="color:rgb(38,127,153)">FILE</span> *<span style="color:rgb(0,16,128)">f</span>)        {</div><div>    <span style="color:rgb(0,0,255)">int</span> <span style="color:rgb(0,16,128)">i</span>, <span style="color:rgb(0,16,128)">ii</span>, <span style="color:rgb(0,16,128)">j</span>, <span style="color:rgb(0,16,128)">jj</span>, <span style="color:rgb(0,16,128)">strsize</span>, <span style="color:rgb(0,16,128)">temp</span>;</div><div>    <span style="color:rgb(0,0,255)">char</span> * <span style="color:rgb(0,16,128)">line</span> = <span style="color:rgb(0,0,255)">NULL</span>;</div><div>    <span style="color:rgb(38,127,153)">size_t</span> <span style="color:rgb(0,16,128)">len</span> = <span style="color:rgb(9,134,88)">0</span>;</div><div>    <span style="color:rgb(38,127,153)">ssize_t</span> <span style="color:rgb(0,16,128)">read</span>;</div><div>    <span style="color:rgb(0,0,255)">char</span> <span style="color:rgb(0,16,128)">ss</span>[<span style="color:rgb(9,134,88)">10</span>];</div><div>    <span style="color:rgb(0,16,128)">temp</span>=<span style="color:rgb(0,16,128)">j</span>=<span style="color:rgb(9,134,88)">0</span>;</div><br><div>    <span style="color:rgb(0,16,128)">ii</span>=<span style="color:rgb(9,134,88)">0</span>;</div><div>    <span style="color:rgb(175,0,219)">while</span> ((<span style="color:rgb(0,16,128)">read</span> = <span style="color:rgb(121,94,38)">getline</span>(&<span style="color:rgb(0,16,128)">line</span>, &<span style="color:rgb(0,16,128)">len</span>, <span style="color:rgb(0,16,128)">f</span>)) != -<span style="color:rgb(9,134,88)">1</span>) {</div><div>        <span style="color:rgb(0,16,128)">jj</span>      = <span style="color:rgb(9,134,88)">4</span>;</div><div>        <span style="color:rgb(0,16,128)">strsize</span> = (<span style="color:rgb(0,0,255)">int</span>) <span style="color:rgb(0,16,128)">read</span>;</div><div>        <span style="color:rgb(175,0,219)">for</span> (<span style="color:rgb(0,16,128)">i</span>=<span style="color:rgb(0,16,128)">strsize</span>-<span style="color:rgb(9,134,88)">1</span>; <span style="color:rgb(0,16,128)">i</span>>=<span style="color:rgb(9,134,88)">0</span>; <span style="color:rgb(0,16,128)">i</span>--){</div><div>            <span style="color:rgb(175,0,219)">if</span> ( <span style="color:rgb(0,16,128)">line</span>[<span style="color:rgb(0,16,128)">i</span>] == (<span style="color:rgb(0,0,255)">int</span>) <span style="color:rgb(9,134,88)">32</span> || <span style="color:rgb(0,16,128)">line</span>[<span style="color:rgb(0,16,128)">i</span>] == (<span style="color:rgb(0,0,255)">int</span>) <span style="color:rgb(9,134,88)">10</span>) { //space or newline</div><div>                <span style="color:rgb(175,0,219)">if</span>(<span style="color:rgb(0,16,128)">i</span> != (<span style="color:rgb(0,16,128)">strsize</span>-<span style="color:rgb(9,134,88)">1</span>)) {  </div><div>                    <span style="color:rgb(0,16,128)">a</span>[<span style="color:rgb(0,16,128)">ii</span>][<span style="color:rgb(0,16,128)">jj</span>] = <span style="color:rgb(0,16,128)">temp</span>;</div><div>                    <span style="color:rgb(0,16,128)">jj</span>--;</div><div>                }</div><div>                <span style="color:rgb(0,16,128)">j</span>=<span style="color:rgb(9,134,88)">0</span>;</div><div>                <span style="color:rgb(0,16,128)">temp</span>=<span style="color:rgb(9,134,88)">0</span>;</div><div>            }</div><div>            <span style="color:rgb(175,0,219)">else</span>     {</div><div>                <span style="color:rgb(0,16,128)">ss</span>[<span style="color:rgb(9,134,88)">0</span>] = <span style="color:rgb(0,16,128)">line</span>[<span style="color:rgb(0,16,128)">i</span>];</div><div>                <span style="color:rgb(0,16,128)">temp</span> += <span style="color:rgb(121,94,38)">atoi</span>(<span style="color:rgb(0,16,128)">ss</span>)*( (<span style="color:rgb(0,0,255)">int</span>) <span style="color:rgb(121,94,38)">pow</span>((<span style="color:rgb(0,0,255)">double</span>)<span style="color:rgb(9,134,88)">10</span>, (<span style="color:rgb(0,0,255)">double</span>)<span style="color:rgb(0,16,128)">j</span>) );</div><div>                <span style="color:rgb(0,16,128)">j</span>++;</div><div>            }   </div><div>        }</div><div>        <span style="color:rgb(0,16,128)">ii</span>++;</div><div>    }</div><div>    <span style="color:rgb(175,0,219)">return</span> (<span style="color:rgb(0,16,128)">ii</span>);    </div><div>}</div></div></div></div><br><div class="gmail_quote"><div dir="ltr"></div><div dir="ltr" class="gmail_attr">On Fri, Aug 12, 2022 at 1:57 PM Chris Clepper <<a href="mailto:cgclepper@gmail.com" target="_blank">cgclepper@gmail.com</a>> wrote:<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 dir="ltr"><div>That issue only relates to data corruption in the case of major failures like power loss and kernel panics.  In most of those situations some data loss is not only expected but also the least of your concerns.</div><div><br></div><div>As for the original topic, the first thing to check is the usual problems moving between architectures like endianess, definition of data structures (is long really 32 bits, double 64 bits, etc), memory alignment and compiler settings.  Does the code work with all of the optimizations turned off?<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Aug 12, 2022 at 5:58 AM Bastiaan van den Berg <<a href="mailto:buzz@spacedout.nl" target="_blank">buzz@spacedout.nl</a>> wrote:<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 dir="ltr">Did you read that M1's storage has so much cache + lies to the OS about cache commitments, leading to data corruption sometimes?   <a href="https://twitter.com/marcan42/status/1494213855387734019" target="_blank">https://twitter.com/marcan42/status/1494213855387734019</a><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Aug 12, 2022 at 6:14 AM Jaime Oliver <<a href="mailto:jaime.oliver2@gmail.com" target="_blank">jaime.oliver2@gmail.com</a>> wrote:<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 dir="auto">Dear all,<div dir="auto"><br></div><div dir="auto">I have a c external that compiles and runs fine on windows, Linux, and Mac Intel systems, but while the exact same code compiles ok on a Mac M1 system, it runs with errors.</div><div dir="auto"><br></div><div dir="auto">I am trying to figure out the bug, but wonder if anyone has come across something like this? The external itself is not particularly complex. It writes and reads text files, does basic arithmetic, and uses arrays of various sizes.</div><div dir="auto"><br></div><div dir="auto">Does anyone have any suggestions of where to look first?</div><div dir="auto"><br></div><div dir="auto">Best,</div><div dir="auto"><br></div><div dir="auto">Jaime</div></div>
_______________________________________________<br>
<a href="mailto:Pd-list@lists.iem.at" target="_blank">Pd-list@lists.iem.at</a> mailing list<br>
UNSUBSCRIBE and account-management -> <a href="https://lists.puredata.info/listinfo/pd-list" rel="noreferrer" target="_blank">https://lists.puredata.info/listinfo/pd-list</a><br>
</blockquote></div>
_______________________________________________<br>
<a href="mailto:Pd-list@lists.iem.at" target="_blank">Pd-list@lists.iem.at</a> mailing list<br>
UNSUBSCRIBE and account-management -> <a href="https://lists.puredata.info/listinfo/pd-list" rel="noreferrer" target="_blank">https://lists.puredata.info/listinfo/pd-list</a><br>
</blockquote></div>
_______________________________________________<br>
<a href="mailto:Pd-list@lists.iem.at" target="_blank">Pd-list@lists.iem.at</a> mailing list<br>
UNSUBSCRIBE and account-management -> <a href="https://lists.puredata.info/listinfo/pd-list" rel="noreferrer" target="_blank">https://lists.puredata.info/listinfo/pd-list</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr"><div dir="ltr">**********************<div>Jaime E Oliver LR<br><a href="http://www.jaimeoliver.pe" target="_blank">www.jaimeoliver.pe</a><br><br></div></div></div>
<span>_______________________________________________</span><br><span>Pd-list@lists.iem.at mailing list</span><br><span>UNSUBSCRIBE and account-management -> https://lists.puredata.info/listinfo/pd-list</span><br></div></body></html>