Re: Require C11 in PHP 8.4
| From: | Stephen Reay | Date: | Fri, 02 Aug 2024 05:50:30 +0000 |
| Subject: | Re: Require C11 in PHP 8.4 | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-124710@lists.php.net to get a copy of this message | ||
> On 2 Aug 2024, at 05:26, Derick Rethans <derick@php.net> wrote:
>
> On 1 August 2024 22:57:36 BST, Ilija Tovilo <tovilo.ilija@gmail.com
> <mailto:tovilo.ilija@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
Hi,
According to https://releases.llvm.org/3.1/docs/ClangReleaseNotes.html#cchanges,
Clang 3.1 added C11.
According to https://trac.macports.org/wiki/XcodeVersionInfo,
Clang 3.1 shipped with Xcode 4.3.3, in May 2012.
In terms of confirming this, the oldest macOS VM I have quick access to is running Sierra (from
2016, last OS update in 2019), and default install now for Clang on that VM is 9.0.0
Hope this helps
Cheers
Stephen