ZSTR cast to union not working on g++

php.internals

Cristiano Duarte

20 years ago
In zend.h, ZSTR is defined like this: typedef union _zstr { char *s; UChar *u; void *v; } zstr; #ifdef __GNUC__ # define ZSTR(x) ((zstr)(x)) # define NULL_ZSTR ZSTR((void*)NULL) # define EMPTY_ZSTR ZSTR("\0\0") #else extern ZEND_API zstr null_zstr; extern ZEND_API zstr empty_zstr; static inline zstr _to_zstr(void *v) { zstr ret; ret.v = v; return ret; } # define ZSTR(x) _to_zstr(x) # define NULL_ZSTR null_zstr # define EMPTY_ZSTR empty_zstr #endif The problem is that g++ is also __GNUC__ and I just can't get g++ to compile a code like this: char *c="I am not working!"; zstr z = ZSTR(c); So I found at gcc.gnu.org that the "Cast to Union" GNU extension is just for C not C++, here is the patch to the current CVS: Index: Zend/zend.h =================================================================== RCS file: /repository/ZendEngine2/zend.h,v retrieving revision 1.316 diff -u -u -r1.316 zend.h --- Zend/zend.h 3 Mar 2006 09:56:47 -0000 1.316 +++ Zend/zend.h 13 Mar 2006 23:29:45 -0000 @@ -246,7 +246,7 @@ void *v; } zstr; -#ifdef __GNUC__ +#if defined(__GNUC__) && ! defined(__GNUG__) # define ZSTR(x) ((zstr)(x)) # define NULL_ZSTR ZSTR((void*)NULL) # define EMPTY_ZSTR ZSTR("\0\0") Regards, Cristiano Duarte

Cristiano Duarte

20 years ago
Should I have opened a BUG report instead ? It's just an one line patch... Let me know if I need to open a BUG report. Regards, Cristiano Duarte