Skip to content

Commit 0e657f8

Browse files
committed
Fix compilation with C23
GCC 15 has been released (fairly) recently, and with it come C23 features such as built-in `bool` types, which obviate the need for defining these in each code-base. In our case, this also causes compilation errors with GCC 15 (unless the `-std=gnu17` flag is passed), e.g.: ./test.go:16:17: error: two or more data types in declaration specifiers 16 | typedef uint8_t bool; | ^~~~ This commit wraps these `typedef` declarations in `__STDC_VERSION__` checks, skipping if the version is C23 or over.
1 parent 04cb87b commit 0e657f8

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

bind/gen.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ package main
5252
%[3]s
5353
// #define Py_LIMITED_API // need full API for PyRun*
5454
#include <Python.h>
55+
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 202311L)
5556
typedef uint8_t bool;
57+
#endif
5658
// static inline is trick for avoiding need for extra .c file
5759
// the following are used for build value -- switch on reflect.Kind
5860
// or the types equivalent
@@ -410,7 +412,7 @@ build:
410412
$(GOIMPORTS) -w %[1]s.go
411413
# this will otherwise be built during go build and may be out of date
412414
- rm %[1]s.c
413-
echo "typedef uint8_t bool;" > %[1]s_go.h
415+
printf "#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 202311L)\ntypedef uint8_t bool;\n#endif\n" > %[1]s_go.h
414416
# this will fail but is needed to generate the .c file that then allows go build to work
415417
- $(PYTHON) build.py >/dev/null 2>&1
416418
# generate %[1]s_go.h from %[1]s.go -- unfortunately no way to build .h only

cmd_build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func runBuild(mode bind.BuildMode, cfg *BuildCfg) error {
125125

126126
if mode == bind.ModeExe {
127127
of, err := os.Create(buildname + ".h") // overwrite existing
128-
fmt.Fprintf(of, "typedef uint8_t bool;\n")
128+
fmt.Fprintf(of, "#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 202311L)\ntypedef uint8_t bool;\n#endif\n")
129129
of.Close()
130130

131131
fmt.Printf("%v build.py # will fail, but needed to generate .c file\n", cfg.VM)

0 commit comments

Comments
 (0)