Skip to content

Conversation

jengelh
Copy link
Contributor

@jengelh jengelh commented Jun 18, 2025

GCC 15/-std=c23:

src/bool.c:332:22: error: passing argument 1 of 'InitHandlerFunc' from incompatible pointer type [-Wincompatible-pointer-types]
  332 |     InitHandlerFunc( ReturnTrue1, "src/bool.c:ReturnTrue1" );
[   19s] src/calls.h:416:30: note: expected ‘ObjFunc’ {aka ‘struct OpaqueBag * (*)(void)’} but argument is of type ‘struct OpaqueBag * (*)(struct OpaqueBag *, struct OpaqueBag *)’

Declarators with unspecified arguments int f(); got socially deprecated with C89; since then, one can write f(void) for actual zero-argument functions, and f(T, ...) for varargs functions.

C23 finally yanked declarators with unspecified arguments.

Different pointer types may have different size. So you can't have one pointer type for "all kinds of functions" in plain C. Nor C++ for that matter; some use of templates/RTTI would be necessary (possibly hidden in something like std::any, but still).

Or rely on platform-specific extensions, e.g. POSIX>=2001 guarantees that sizeof(void*) >= sizeof(any function pointer). This is what this patch does.

Fixes: #5857 #6009

Text for release notes

GCC 15 support

@fingolfin fingolfin changed the title Stop using declarators with unspecified arguments Fix build issues with GCC 15 Jun 18, 2025
@fingolfin fingolfin added the release notes: use title For PRs: the title of this PR is suitable for direct use in the release notes label Jun 18, 2025
@fingolfin fingolfin changed the title Fix build issues with GCC 15 Fix build issues with GCC 15 resp. the C23 standard Jun 18, 2025
@fingolfin
Copy link
Member

fingolfin commented Jun 18, 2025

Thanks for the patch. I adjusted the PR title to be useable for our user-facing release notes.

Different pointer types may have different size.

That's a red herring. do you know any non-exotic systems (i.e. no microcontrollers, no DOS/Windows 3.1, etc.) in current use where this is the case?

In any case: For any architecture GAP runs on, this (every pointer fits into a void *) is satisfied. And conversely, this is deeply ingrained in the code base, and so any architecture where this does not hold will likely not be able to run GAP anyway.

So you can't have one pointer type for "all kinds of functions" in plain C.

That is a true statement and why we have e.g. ObjFunc_1ARGS etc. -- values of ObjFunc type are never directly "called".

GCC 15/-std=c23:

```
src/bool.c:332:22: error: passing argument 1 of 'InitHandlerFunc' from incompatible pointer type [-Wincompatible-pointer-types]
  332 |     InitHandlerFunc( ReturnTrue1, "src/bool.c:ReturnTrue1" );
[   19s] src/calls.h:416:30: note: expected ‘ObjFunc’ {aka ‘struct OpaqueBag * (*)(void)’} but argument is of type ‘struct OpaqueBag * (*)(struct OpaqueBag *, struct OpaqueBag *)’
```

Declarators with unspecified arguments `int f();` got socially
deprecated with C89; since then, one can write `f(void)` for actual
zero-argument functions, and `f(T, ...)` for varargs functions.

C23 finally yanked declarators with unspecified arguments.

Different pointer types may have different size. So you can't have
one pointer type for "all kinds of functions" in plain C. Nor C++ for
that matter; some use of templates/RTTI would be necessary (possibly
hidden in something like std::any, but still).

Or rely on platform-specific extensions, e.g. POSIX>=2001 guarantees
that sizeof(void*) >= sizeof(any function pointer) and that
conversion is meaningful; this is effectively mandated by the
presence of dlsym(). For Windows, sizeof(FARPROC) >= sizeof(afp),
effectively mandated by GetProcAddress().

Fixes: gap-system#5857 gap-system#6009
@jengelh jengelh changed the title Fix build issues with GCC 15 resp. the C23 standard Fix build issues in C23 standards mode as exhibited by GCC 15 default flags Jun 18, 2025
@jengelh
Copy link
Contributor Author

jengelh commented Jun 18, 2025

any non-exotic systems

Probably not: Flat addressing has been the norm since the 386.

adjusted the PR title

"resp." is a mistranslation, so I removed it.

@fingolfin fingolfin changed the title Fix build issues in C23 standards mode as exhibited by GCC 15 default flags Fix build issues when compiling GAP with GCC 15 Jun 18, 2025
@fingolfin fingolfin enabled auto-merge (squash) June 18, 2025 15:43
@fingolfin fingolfin disabled auto-merge June 18, 2025 15:58
@fingolfin
Copy link
Member

OK, so this breaks C++ code in some GAP packages. That will have to be addressed before merging this. I'll trigger a package distro CI run against this branch to figure out which packages are affected.

@ChrisJefferson
Copy link
Contributor

I agree we should just switch to void*, there is no way GAP would work on a platform where void* is a different size to a function pointer without significant cleanup. It's a shame there isn't a better way to fix this from a type-system point of view, but let's make sure it compiles everywhere.

I have released a new profiling release (2.6.1) which should work with this PR once it is picked up, which will help with testing.

Copy link
Member

@fingolfin fingolfin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally all packages are passing 🎉

@fingolfin fingolfin merged commit 084b8fb into gap-system:master Jul 17, 2025
125 of 141 checks passed
@fingolfin fingolfin added kind: bug Issues describing general bugs, and PRs fixing them topic: build system labels Aug 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-to-4.14 kind: bug Issues describing general bugs, and PRs fixing them release notes: use title For PRs: the title of this PR is suitable for direct use in the release notes topic: build system topic: kernel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build failure with GCC 15 (incompatible pointer types)
3 participants