# ZSTR cast to union not working on g++

- Thread: https://externals.io/message/22387
- Original archive: https://news-web.php.net/php.internals/22387
- Started by Cristiano Duarte on 2006-03-13T23:34:51+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #22387 — Cristiano Duarte — 2006-03-13T23:34:51+00:00

URL: https://externals.io/message/22387#22387

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

---

## #22423 — Cristiano Duarte — 2006-03-14T18:08:19+00:00

URL: https://externals.io/message/22387#22423 · In reply to: #22387

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
