On 1 August 2024 22:57:36 BST, Ilija Tovilo <tovilo.il...@gmail.com> wrote: >Hi everyone > >We've gotten a bug report about compile errors in the PHP 8.4 alpha on >old C99 compilers (and on some modern compilers when passing the >-std=c99 flag). Specifically, C99 does not support typedef >redeclarations, which is a C11 feature. > >```c >// some_header.h >typedef struct _zval_struct zval; >void some_func(zval *zv); > >// zend_types.h >struct _zval_struct { ... }; >typedef struct _zval_struct zval; >``` > >Some headers might want to forward declare zval so that zend_types.h >doesn't have to be included. The two primary reasons you might want to >avoid that are 1. to reduce compile times if the header is very large >and 2. to prevent recursive header dependencies. > >However, in C99 this code is actually illegal if both of these headers >end up being included, because redeclarations of typedefs are not >allowed. To fix it, the typedef must be removed and the signatures >must refer to the struct directly. > >```c >// some_header.h >struct _zval_struct; >void some_func(struct _zval_struct *zv); >``` > >I started fixing these in a PR [1] which required more changes than >expected. After a short discourse, we were wondering whether it might >be better to switch to a newer C standard instead. Our coding >standards [2] currently specify that compiling php-src requires C99. >The Unix installation page on php.net [3] claims it is ANSI C, which >is certainly outdated. There have been suggestions to require C11 for >a while, which should be well supported by all compilers shipped with >maintained distributions. > >GCC gained support for C11 in 4.7 [4], LLVM Clang in 3.1, both >released in 2012. For context, Debian Bullseye comes with GCC 10.2 >[5], Ubuntu Focal Fossa comes with GCC 9.3 [6], RHEL 8 comes with GCC >8.x [7]. Even Debian wheezy (out of extended LTS support) or Ubuntu 14.04 have GCC 4.7, so that seems OK.
How about Clang (for OSX) though? I can't check that easily. cheers Derick