[L2Ork-dev] End-run around indecipherable C standard docs

Matt Barber brbrofsvl at gmail.com
Wed Jun 6 18:05:30 EDT 2018


Yes, technically according to the c standard, I'm pretty sure that you are
supposed to extract only the last type input into the union, but that it's
the programmer's responsibility and that attempting to extract something
else has implementation-dependent behavior. It would be weird for a
compiler to implement it in any other way – the thing that could sometimes
be tricky is alignment when the types are not the same size. Pretty sure
there's no problem with any mainstream compiler.

On Wed, Jun 6, 2018 at 4:35 PM, Jonathan Wilkes <jon.w.wilkes at gmail.com>
wrote:

> Hi list,
>
> It appears that Purr Data uses the following compilers:
>
> 1. gcc under Linux
> 2. clang under OSX
> 3. gcc via msys2 on Windows
>
> It appears to me that gcc has an extension that allows us
> to do type punning through unions:
>
> http://mail-index.netbsd.org/tech-kern/2003/08/11/0001.html
>
> It also appears that clang copies this gcc extension.
>
> So on all the supported platforms, we should be covered
> if we use union type punning.
>
> The only alternative to caring about all these compiler
> implementations is apparently to cast to char* and use
> memcpy, which is stupid.
>
> Can I reasonably move on at this point without having to
> decode C99 scrolls (and the even more boring reading of
> web blogs attempting to interpret said scrolls)?
>
> -Jonathan
> _______________________________________________
> L2Ork-dev mailing list
> L2Ork-dev at disis.music.vt.edu
> https://disis.music.vt.edu/listinfo/l2ork-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://disis.music.vt.edu/pipermail/l2ork-dev/attachments/20180606/7e657b8d/attachment.html>


More information about the L2Ork-dev mailing list