[PATCH v2 2/2] Fix compiling with C23 enabled compilers
Anup Patel
anup at brainfault.org
Sat Dec 21 08:20:05 PST 2024
On Fri, Dec 13, 2024 at 9:44 AM Michael Neuling
<michaelneuling at tenstorrent.com> wrote:
The subject prefix should be "include: sbi:"
>
> C23 pre-definies bool so we need to gate our defines.
s/definies/defines/
>
> Signed-off-by: Michael Neuling <michaelneuling at tenstorrent.com>
> ---
> include/sbi/sbi_types.h | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/include/sbi/sbi_types.h b/include/sbi/sbi_types.h
> index a9943d299c..f051695ffd 100644
> --- a/include/sbi/sbi_types.h
> +++ b/include/sbi/sbi_types.h
> @@ -44,7 +44,12 @@ typedef unsigned long long uint64_t;
> #error "Unexpected __riscv_xlen"
> #endif
>
> +#if __STDC_VERSION__ < 202311L
I was able to reproduce the compilation issue with GCC and "-std=gnu2x"
option but I had to adjust the above #if comparison with 202000L.
> typedef int bool;
I agree with Jessica. We should use _Bool to be consistent
across C standards.
> +#define true 1
> +#define false 0
> +#endif
> +
> typedef unsigned long ulong;
> typedef unsigned long uintptr_t;
> typedef unsigned long size_t;
> @@ -61,9 +66,6 @@ typedef uint32_t be32_t;
> typedef uint64_t le64_t;
> typedef uint64_t be64_t;
>
> -#define true 1
> -#define false 0
> -
> #define NULL ((void *)0)
>
> #define __packed __attribute__((packed))
> --
> 2.34.1
>
I have taken care of the above comments and tested it with
both GCC and LLVM.
Reviewed-by: Anup Patel <anup at brainfault.org>
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
More information about the opensbi
mailing list