Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124710 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 2A8941A00B7 for ; Fri, 2 Aug 2024 05:50:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1722577952; bh=bUIoWwAUJUD3M6+uKtFanUTrREj3T0O7dDZ99r1oVDY=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=ah9d3vAXPxeaLx9AOoamMQ+dKTDMlGwpO41Y+Ssp1THUuyo1fmsEAwG2BNiJx3Gkv E8w9nmhVOsLMk174/SPcXl7BRUklXBj22NfW9wIM0euzm1TCuk/WHxDHqQJFHE18GG 09yKWQlzOjqYXeyMp5CtOYuMmfcQWhwmX6vXkMQ6HrXrgZadPGTnRcdKIUWjkx7WKU UxLXPuDNqr8o1zU703Y0w063xj9T4BKDCTrECz7K+MS8eA/MJIvdMIauuLVEk089Cm O9zDr2+R/+rFouvd3qReR9xXb4uNeotjeiwviLqAe8KHkH+daUaBLlP1Zz5VGKUD+f FL63px1Jper5Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CA279180072 for ; Fri, 2 Aug 2024 05:52:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,DMARC_MISSING, HTML_MESSAGE,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail1.25mail.st (mail1.25mail.st [206.123.115.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 2 Aug 2024 05:52:30 +0000 (UTC) Received: from smtpclient.apple (unknown [49.48.221.22]) by mail1.25mail.st (Postfix) with ESMTPSA id 6071460368; Fri, 2 Aug 2024 05:50:44 +0000 (UTC) Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_5E91BBD0-0B61-4EDC-85C9-1355D2EF1D4B" Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3776.700.51\)) Subject: Re: [PHP-DEV] Require C11 in PHP 8.4 Date: Fri, 2 Aug 2024 12:50:30 +0700 In-Reply-To: <30A26099-E558-4C99-B47A-47E30D5CA456@php.net> Cc: Derick Rethans To: php internals References: <30A26099-E558-4C99-B47A-47E30D5CA456@php.net> X-Mailer: Apple Mail (2.3776.700.51) From: php-lists@koalephant.com (Stephen Reay) --Apple-Mail=_5E91BBD0-0B61-4EDC-85C9-1355D2EF1D4B Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > On 2 Aug 2024, at 05:26, Derick Rethans wrote: >=20 > On 1 August 2024 22:57:36 BST, Ilija Tovilo > wrote: >> Hi everyone >>=20 >> 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=3Dc99 flag). Specifically, C99 does not support typedef >> redeclarations, which is a C11 feature. >>=20 >> ```c >> // some_header.h >> typedef struct _zval_struct zval; >> void some_func(zval *zv); >>=20 >> // zend_types.h >> struct _zval_struct { ... }; >> typedef struct _zval_struct zval; >> ``` >>=20 >> 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. >>=20 >> 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. >>=20 >> ```c >> // some_header.h >> struct _zval_struct; >> void some_func(struct _zval_struct *zv); >> ``` >>=20 >> 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. >>=20 >> 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].=20 >=20 > Even Debian wheezy (out of extended LTS support) or Ubuntu 14.04 have = GCC 4.7, so that seems OK.=20 >=20 > How about Clang (for OSX) though? I can't check that easily.=20 >=20 > cheers=20 > Derick=20 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.=20 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=20 --Apple-Mail=_5E91BBD0-0B61-4EDC-85C9-1355D2EF1D4B Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii

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> = 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=3Dc99 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://trac.macp= orts.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

<= div>Stephen 

= --Apple-Mail=_5E91BBD0-0B61-4EDC-85C9-1355D2EF1D4B--