arch/powerpc: Remove redundant typedef for bool
PATCH 1/1 arch/powerpc: Remove redundant typedef for bool
Hi,
I noticed that a patch addressing the same issue has been proposed by Michal Suchanek:
https://lore.kernel.org/linuxppc-dev/[email protected]/T/#t
The existing patch addresses the compilation error by modifying the Makefile to use gnu11 with BOOTTARGETFLAGS. This is a practical approach to avoid the error in the short term.
This patch builds on that work by providing a long-term solution that ensures compatibility with C23 while maintaining backward compatibility. Specifically:
- It uses __STDC_VERSION__ to conditionally define the bool typedef only for pre-C23 standards.
- It ensures that the code is future-proof and ready for upcoming C23 standards, where bool, true, and false are reserved keywords.
- It avoids reliance on compiler-specific flags, making the code more portable and standards-compliant.
Changlog:
- Adding version check via __STDC_VERSION__
- If __STDC_VERSION__ < C23, 'typedef int bool' is defined as usual
- If __STDC_VERSION__ >= C23, the typedef redundancy is removed
The patch has been tested with:
- gcc (GCC) 15.0.1 20250228 (Red Hat 15.0.1-0)
- gcc (GCC) 14.2.1 20250110 (Red Hat 14.2.1-7)
Thanks,
Misbah Anjum N
Misbah Anjum N (1):
arch/powerpc: Remove redundant typedef for bool
arch/powerpc/boot/types.h | 2 ++ 1 file changed, 2 insertions(+)
Signature · 1 line
2.49.0
PATCH 1/1 arch/powerpc: Remove redundant typedef for bool
The custom 'bool' typedef in arch/powerpc/boot/types.h is incompatible with the C23 standard, where 'bool', 'true', and 'false' are now reserved keywords. With newer GCC versions (such as GCC 15), redefining 'bool' leads to compilation errors. For example:
error: 'bool' cannot be defined via 'typedef'
Since 'stdbool.h' is already included and provides a standard definition for 'bool', this typedef is redundant and can be removed to avoid conflicts.
Compilation Error:
$ make -j$(nproc)
....
In file included from arch/powerpc/boot/ops.h:13,
from arch/powerpc/boot/cuboot.c:12:
arch/powerpc/boot/types.h:43:13: error: ‘bool’ cannot be defined via ‘typedef’
43 | typedef int bool;
| ^~~~
arch/powerpc/boot/types.h:43:13: note: ‘bool’ is a keyword with ‘-std=c23’ onwards
arch/powerpc/boot/types.h:43:1: warning: useless type name in empty declaration
43 | typedef int bool;
| ^~~~~~~
....
make[2]: *** [arch/powerpc/boot/Makefile:235: arch/powerpc/boot/devtree.o] Error 1
make[2]: *** [arch/powerpc/boot/Makefile:235: arch/powerpc/boot/ofconsole.o] Error 1
make[2]: *** [arch/powerpc/boot/Makefile:235: arch/powerpc/boot/ns16550.o] Error 1
make[2]: *** [arch/powerpc/boot/Makefile:235: arch/powerpc/boot/main.o] Error 1
make[1]: *** [arch/powerpc/Makefile:236: zImage] Error 2
make: *** [Makefile:251: __sub-make] Error 2--- arch/powerpc/boot/types.h | 2 ++ 1 file changed, 2 insertions(+)
arch/powerpc/boot/types.h +2 -0
@@ -40,7 +40,9 @@ typedef s64 int64_t;#define min_t (type, a, b) min(((type) a), ((type) b))#define max_t (type, a, b) max(((type) a), ((type) b)) +#if !defined(__STDC_VERSION__) || __STDC_VERSION__ <202300L typedef int bool ; +#endif #ifndef true#define true 1
Signature · 1 line
2.49.0
Quoted 32 lines · Misbah Anjum N
Hi,
I noticed that a patch addressing the same issue has been proposed by Michal Suchanek:
https://lore.kernel.org/linuxppc-dev/[email protected]/T/#tThe existing patch addresses the compilation error by modifying the
Makefileto usegnu11withBOOTTARGETFLAGS. This is a practical approach to avoid the error in the short term.This patch builds on that work by providing a long-term solution that ensures compatibility with C23 while maintaining backward compatibility. Specifically:
- It uses__STDC_VERSION__to conditionally define thebooltypedef only for pre-C23 standards.
- It ensures that the code is future-proof and ready for upcoming C23 standards, wherebool,true, andfalseare reserved keywords.
- It avoids reliance on compiler-specific flags, making the code more portable and standards-compliant.Changlog:
- Adding version check via__STDC_VERSION__
- If__STDC_VERSION__< C23, 'typedef int bool' is defined as usual
- If__STDC_VERSION__>= C23, the typedef redundancy is removedThe patch has been tested with:
- gcc (GCC) 15.0.1 20250228 (Red Hat 15.0.1-0)
- gcc (GCC) 14.2.1 20250110 (Red Hat 14.2.1-7)Thanks,
Misbah Anjum N
Quoted 6 lines
Misbah Anjum N (1):
arch/powerpc: Remove redundant typedef for boolarch/powerpc/boot/types.h | 2 ++ 1 file changed, 2 insertions(+)
Quoted 3 lines
Signature · 1 line
2.49.0