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.

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to