On Sat, May 18, 2024 at 02:43:52PM +0200, Edgar Bonet wrote: > Hello! > > Yesterday, I wrote: > > My understanding is that the compiler considers 'int' and 'long' to be > > incompatible types [... On ILP32,] 'size_t' being an 'unsigned int', > > it is incompatible with 'long'. > > > > On LP64 (your typical 64-bit Linux/Mac), 'size_t' is a 'unsigned > > long', which is compatible with 'long' but for the signedness warning. > > I just did a small experiment to confirm all this. It shows that this > “incompatible pointer type” error is specific to GCC 14 compiling for > 32-bit targets. I natively compiled the following C file: > > #include <stddef.h> > > void callee(size_t *); > > void caller(void) > { > long n; > callee(&n); > } > > on three different systems: > > 1. gcc 11.4 / Ubuntu 22.04 / x86_64 (desktop PC, 64 bits) > 2. gcc 12.2 / Debian 12 / i686 (Acer Aspire One A110L, 32 bits) > 3. gcc 10.2 / Raspbian 11 / armv6l (Raspberry Pi model B, 32 bits) > > On the 64-bit PC, the compiler issues no warnings unless I explicitly > request them (e.g., with -Wall). If I do so, I get the signedness > warning: > > warning: pointer targets in passing argument 1 of ‘callee’ > differ in signedness [-Wpointer-sign] > note: expected ‘size_t *’ {aka ‘long unsigned int *’} > but argument is of type ‘long int *’ > > On both 32-bit systems, I get the following warning even with no -W* > option: > > warning: passing argument 1 of ‘callee’ > from incompatible pointer type [-Wincompatible-pointer-types] > note: expected ‘size_t *’ {aka ‘unsigned int *’} > but argument is of type ‘long int *’ > > This shows that: > > * ‘size_t’ is ‘unsigned int’ on ILP32 and ‘long unsigned int’ on LP64 > > * ‘int’ and ’long int’ are considered incompatible even on ILP32, > where they have the same size. > > What changes with GCC 14 is that the “incompatible pointer type” warning > has been changed to an error. The GCC 14 porting guide states:[1]
Thanks for clarification and testing, this matches my observation. Concerning type compatibility, C11 gives a definition on what types are compatible. From the n1548 draft, §6.2.7: : Two types have compatible type if their types are the same. Following "§6.2.5 Types", int and long belong to different types (regardless of signedness). An §6.7.8 example further clarifies compatible type definitions: : typedef struct s1 { int x; } t1, *tp1; : typedef struct s2 { int x; } t2, *tp2; : : type t1 and the type pointed to by tp1 are compatible. Type t1 is : also compatible with type struct s1, but not compatible with the : types struct s2, t2, the type pointed to by tp2, or int. On Thu, May 16, 2024 at 11:25:33AM +0200, Edgar Bonet wrote: > # HG changeset patch > # User Edgar Bonet <bo...@grenoble.cnrs.fr> > # Date 1715850910 -7200 > # Thu May 16 11:15:10 2024 +0200 > # Node ID c2c3b0d74b1a7d3f967421c72760b5c573afcd81 > # Parent 89093b003fcb54c7f8dc66042f17bc4dea4e7709 > Fix compile error in configure script > > Building with GCC 14 fails at the configure step with: > > ./configure: error: libatomic_ops library was not found. > > The error is not caused by a missing library, but by an unrelated > "incompatible pointer type" error in the test program: > > ... > checking for atomic_ops library > objs/autotest.c: In function 'main': > objs/autotest.c:9:48: error: passing argument 1 of 'AO_compare_and_swap' > from incompatible pointer type [-Wincompatible-pointer-types] > > Fix the error by using the correct pointer types. > > Signed-off-by: Edgar Bonet <bo...@grenoble.cnrs.fr> > > diff -r 89093b003fcb -r c2c3b0d74b1a auto/lib/libatomic/conf > --- a/auto/lib/libatomic/conf Fri May 03 20:26:05 2024 +0400 > +++ b/auto/lib/libatomic/conf Thu May 16 11:15:10 2024 +0200 > @@ -19,7 +19,7 @@ > #include <atomic_ops.h>" > ngx_feature_path= > ngx_feature_libs="-latomic_ops" > - ngx_feature_test="long n = 0; > + ngx_feature_test="AO_t n = 0; > if (!AO_compare_and_swap(&n, 0, 1)) > return 1; > if (AO_fetch_and_add(&n, 1) != 1) I like the patch, but would like to adjust the commit log: there some styles issues and over-quoting. Also, there is no mention of Clang behaviour. Please see below. # HG changeset patch # User Edgar Bonet <bo...@grenoble.cnrs.fr> # Date 1715850910 -7200 # Thu May 16 11:15:10 2024 +0200 # Node ID 8d35d9cfef17f350f750049940e22d1d61d55a6a # Parent 5a5c01ec6f58d413e9867ace5d0065bb43484a11 Configure: fixed building libatomic test. Using "long *" instead of "AO_t *" leads either to -Wincompatible-pointer-types or -Wpointer-sign warnings, depending on whether long and size_t are compatible types (e.g., ILP32 versus LP64 data models). Notably, -Wpointer-sign warnings are enabled by default in Clang only, and -Wincompatible-pointer-types is an error starting from GCC 14. Signed-off-by: Edgar Bonet <bo...@grenoble.cnrs.fr> _______________________________________________ nginx-devel mailing list nginx-devel@nginx.org https://mailman.nginx.org/mailman/listinfo/nginx-devel