Re:How big are PHP arrays (and values) really?
by chadaustin on Friday December 16, 2011 @05:16AM
(#3360240)
Actually, the upcoming C1X standard makes type punning via union legal. In C99, alias analysis works behaves exactly as you said, but using unions to convert between floats and ints is so common that it's legal in C1X, VC++, and I believe gcc.
[ Parent
| on HN ]
Re:How big are PHP arrays (and values) really?
by cygx on Friday December 16, 2011 @05:48AM
(#3360310)
Type-punning through unions is already legal in C99, but there's a known error in Annex J, listing it incorrectly as unspecified behaviour.
Re:How big are PHP arrays (and values) really?
by legooolas on Friday December 16, 2011 @06:10AM
(#3360349)
I stand corrected :/
Re:How big are PHP arrays (and values) really?
by cygx on Friday December 16, 2011 @06:29AM
(#3360386)
Don't feel bad about it - the C standard can be quite subtle, and I've been known to spread lies about it as well.
Things about which I have stumbled somewhat recently:
* restrict-qualified pointer-to-const parameters do not guarantee that the pointed-to object won't be modified as restrict only applies if the pointer is actually used to access the object, which calling code can't know (ie restrict only enables optimizations in the called code and not reordering in calling code)
* functions with differently qualified, but otherwise compatible parameter types have compatible type (which is only mentioned in the last, parenthesized sentence of section 6.7.5.3)
Re:How big are PHP arrays (and values) really?
by legooolas on Friday December 16, 2011 @05:24AM
(#3360261)
gcc does in some cases but not all (see http://gcc.gnu.org/onlinedocs/gcc-4.1.1/gcc/Optimize-Options... but not all).
Still, the current standard says it's not legal so it seems like a bad idea to rely on undefined behaviour...