<div dir="ltr"><div dir="ltr">On Sat, Apr 6, 2019 at 10:54 AM Arda Eden <<a href="mailto:ardaeden@gmail.com">ardaeden@gmail.com</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"><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></div></div></div></blockquote><div>Yes, modern c doesn't like type punning.</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 dir="ltr"><div dir="ltr"><div dir="ltr"><div><div></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></blockquote><div><br></div><div>I think the memcpy statement should be outside the for loop. As it is, it operates the first three times uselessly.</div><div>Using a union would be a bit more efficient as it doesn't copy any memory.<br></div><div><br></div><div>Martin</div><div><br></div></div></div>