<div dir="ltr"><div dir="ltr"><div dir="ltr"><div><div><div>With this method, I got the compiler warning about breaking the strict aliasing rule:</div><div>uint8_t bytes[4] = {12, 34, 56, 78};</div><div>float f = *(float*)bytes;</div></div><div><br></div><div><br></div><div>This is my code, and for now, it is working properly. But I am not sure if this is an efficient way or not.</div><div><br></div><div>typedef struct _xsensparse</div><div>{</div><div>    t_object x_obj;</div><div>    uint8_t wrd[4];</div><div>    t_float o;</div><div>    t_outlet *f1_out, *f2_out;</div><div>} t_xsensparse;</div></div><div><br></div><div>static void xsensparse_list(t_xsensparse *x, t_symbol *s, int argc, t_atom *argv)</div><div>{</div><div>    for(int i=0; i<argc; i++) {</div><div>    x->wrd[i]=(uint8_t)atom_getfloat(argv+3-i);</div><div>    memcpy(&x->o, &x->wrd, 4);<br></div><div>    }</div><div>    post("%f",  x->o);</div><div>    outlet_float(x->f1_out, x->o);</div><div>}<br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Martin Peach <<a href="mailto:chakekatzil@gmail.com">chakekatzil@gmail.com</a>>, 6 Nis 2019 Cmt, 17:36 tarihinde şunu yazdı:<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 dir="ltr">On Sat, Apr 6, 2019 at 10:06 AM Christof Ressi <<a href="mailto:christof.ressi@gmx.at" target="_blank">christof.ressi@gmx.at</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">While type punning through unions is allowed in C, the only way which works in both C and C++ (without breaking the strict aliasing rule) is using memcpy. In such case, the call to memcpy will completely optimized away by every decent compiler.<br>
<br></blockquote><div><br></div><div>But Pd is written in c, so no problem. How does the memcpy thing work? It is also ANSI c. To m it looks just as 'dangerous' as the union method, which I wouldn't call type-punning. 'Raw' type punning would be like:<br></div><div>uint8_t bytes[4] = {12, 34, 56, 78};</div><div>float f = *(float*)bytes;</div><div>But isn't that basically the same as what memcpy does?<br></div><div><br></div><div><br></div><div>Martin</div><br></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 clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Arda EDEN<br>Yıldız Teknik Üniversitesi<br></div><div>Sanat ve Tasarım Fakültesi<br></div><div>Müzik ve Sahne Sanatları Bölümü<br></div><div>Duysal (Ses) Sanatları Tasarımı Programı<br></div><div>İstanbul/Türkiye<br><br></div><div>Yildiz Technical University<br></div><div>Faculty of Art and Design<br></div><div>Department of Music and Performing Arts<br></div><div>Audio Design Program<br></div><div>Istanbul/Turkey<br></div></div></div>