[PD] Getting 32 bit floating point number from 4 sequential bytes

Martin Peach chakekatzil at gmail.com
Sat Apr 6 16:27:23 CEST 2019

On Sat, Apr 6, 2019 at 10:06 AM Christof Ressi <christof.ressi at gmx.at>

> 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.
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:
uint8_t bytes[4] = {12, 34, 56, 78};
float f = *(float*)bytes;
But isn't that basically the same as what memcpy does?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puredata.info/pipermail/pd-list/attachments/20190406/02c46295/attachment-0001.html>

More information about the Pd-list mailing list