Re: Thoughts on C version supported for PHP-Next

From: Date: Sun, 10 May 2015 20:00:13 +0000
Subject: Re: Thoughts on C version supported for PHP-Next
References: 1 2 3 4 5 6 7 8 9 10 11 12 13  Groups: php.internals 
Request: Send a blank email to internals+get-86151@lists.php.net to get a copy of this message
A feature of C11 that would be useful is anonymous unions: struct zval { union { long lval; double dval; }; enum { IS_LONG, IS_DOUBLE } type; }; int main(void) { struct zval zv; zv.lval = 1; zv.type = IS_LONG; return 0; } Again, this is a C11 feature. It is supported by clang, gcc and MSVC. Also note that if you use designated initializers from C99 you can directly initialize it like so: int main(void) { struct zval zv = { .lval = 1, .type = IS_LONG }; return !(zv.lval == 1); } If we are going to have a repository of features this is definitely one I'd like to test since the biggest three compilers all support it and I'd like to see how far the support reaches. Similarly anonymous structs would be useful as well. One specific place I am aware of is the _zend_function union that has a struct named common. If you make this struct anonymous then you can directly access the struct's properties just like you can with _zend_internal_function and _zend_op_array. This makes the polymorphic nature of these structures a bit easier to deal with.

« previous php.internals (#86151) next »