Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 30 Nov 2025 19:22:09 +0000
From:      Robert Clausecker <fuz@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 7998a82d2f99 - main - sys/stdint.h: add C23 _WIDTH macros
Message-ID:  <692c9961.26e23.67d8f161@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch main has been updated by fuz:

URL: https://cgit.FreeBSD.org/src/commit/?id=7998a82d2f99a00086baf64b2a3343ba10f8806d

commit 7998a82d2f99a00086baf64b2a3343ba10f8806d
Author:     Robert Clausecker <fuz@FreeBSD.org>
AuthorDate: 2025-11-19 18:53:07 +0000
Commit:     Robert Clausecker <fuz@FreeBSD.org>
CommitDate: 2025-11-30 19:21:51 +0000

    sys/stdint.h: add C23 _WIDTH macros
    
    The platform-dependent macros are added to the various
    _stdint.h headers, those that are always the same are
    added directly to _stdint.h.
    
    We may want to move the definitions for WCHAR_* and
    WINT_* out of the platform header files as those are
    always the same.
    
    Approved by:    markj (mentor)
    MFC after:      1 month
    Differential Revision:  https://reviews.freebsd.org/D53830
---
 sys/arm/include/_stdint.h     | 23 +++++++++++++++++++++++
 sys/arm64/include/_stdint.h   | 23 +++++++++++++++++++++++
 sys/powerpc/include/_stdint.h | 33 +++++++++++++++++++++++++++++++++
 sys/riscv/include/_stdint.h   | 23 +++++++++++++++++++++++
 sys/sys/stdint.h              | 29 +++++++++++++++++++++++++++++
 sys/x86/include/_stdint.h     | 33 +++++++++++++++++++++++++++++++++
 6 files changed, 164 insertions(+)

diff --git a/sys/arm/include/_stdint.h b/sys/arm/include/_stdint.h
index 9931f8b56ef5..2ebc6ea4f89f 100644
--- a/sys/arm/include/_stdint.h
+++ b/sys/arm/include/_stdint.h
@@ -153,6 +153,29 @@
 #define	WINT_MIN	INT32_MIN
 #define	WINT_MAX	INT32_MAX
 
+#if __ISO_C_VISIBLE >= 2023
+/*
+ * ISO/IEC 9899:2023
+ * 7.22.2 Widths of specified-width integer types
+ */
+#define INT_FAST8_WIDTH		INT32_WIDTH
+#define INT_FAST16_WIDTH	INT32_WIDTH
+#define INT_FAST32_WIDTH	INT32_WIDTH
+#define INT_FAST64_WIDTH	INT64_WIDTH
+#define INTPTR_WIDTH		INT32_WIDTH
+#define INTMAX_WIDTH		INT64_WIDTH
+
+/*
+ * ISO/IEC 9899:2023
+ * 7.22.3 Width of other integer types
+ */
+#define PTRDIFF_WIDTH		INT32_WIDTH
+#define SIG_ATOMIC_WIDTH	INT32_WIDTH
+#define SIZE_WIDTH		INT32_WIDTH
+#define WCHAR_WIDTH		INT32_WIDTH
+#define WINT_WIDTH		INT32_WIDTH
+#endif /* __ISO_C_VISIBLE >= 2023 */
+
 #endif /* !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) */
 
 #endif /* !_MACHINE__STDINT_H_ */
diff --git a/sys/arm64/include/_stdint.h b/sys/arm64/include/_stdint.h
index 0c183bd60dca..0b360b8ab460 100644
--- a/sys/arm64/include/_stdint.h
+++ b/sys/arm64/include/_stdint.h
@@ -155,6 +155,29 @@
 #define	WINT_MIN	INT32_MIN
 #define	WINT_MAX	INT32_MAX
 
+#if __ISO_C_VISIBLE >= 2023
+/*
+ * ISO/IEC 9899:2023
+ * 7.22.2 Widths of specified-width integer types
+ */
+#define INT_FAST8_WIDTH         INT32_WIDTH
+#define INT_FAST16_WIDTH        INT32_WIDTH
+#define INT_FAST32_WIDTH        INT32_WIDTH
+#define INT_FAST64_WIDTH        INT64_WIDTH
+#define INTPTR_WIDTH            INT64_WIDTH
+#define INTMAX_WIDTH            INT64_WIDTH
+
+/*
+ * ISO/IEC 9899:2023
+ * 7.22.3 Width of other integer types
+ */
+#define PTRDIFF_WIDTH           INT64_WIDTH
+#define SIG_ATOMIC_WIDTH        INT64_WIDTH
+#define SIZE_WIDTH              INT64_WIDTH
+#define WCHAR_WIDTH             INT32_WIDTH
+#define WINT_WIDTH              INT32_WIDTH
+#endif /* __ISO_C_VISIBLE >= 2023 */
+
 #endif /* !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) */
 
 #endif /* !_MACHINE__STDINT_H_ */
diff --git a/sys/powerpc/include/_stdint.h b/sys/powerpc/include/_stdint.h
index 67719432259d..983db38ccf25 100644
--- a/sys/powerpc/include/_stdint.h
+++ b/sys/powerpc/include/_stdint.h
@@ -195,6 +195,39 @@
 #define	WINT_MIN	INT32_MIN
 #define	WINT_MAX	INT32_MAX
 
+#if __ISO_C_VISIBLE >= 2023
+/*
+ * ISO/IEC 9899:2023
+ * 7.22.2 Widths of specified-width integer types
+ */
+#define INT_FAST8_WIDTH		INT32_WIDTH
+#define INT_FAST16_WIDTH	INT32_WIDTH
+#define INT_FAST32_WIDTH	INT32_WIDTH
+#define INT_FAST64_WIDTH	INT64_WIDTH
+#ifdef __LP64__
+#define INTPTR_WIDTH		INT64_WIDTH
+#else
+#define INTPTR_WIDTH		INT32_WIDTH
+#endif
+#define INTMAX_WIDTH		INT64_WIDTH
+
+/*
+ * ISO/IEC 9899:2023
+ * 7.22.3 Width of other integer types
+ */
+#ifdef	__LP64__
+#define PTRDIFF_WIDTH		INT64_WIDTH
+#define SIG_ATOMIC_WIDTH	INT64_WIDTH
+#define SIZE_WIDTH		INT64_WIDTH
+#else
+#define PTRDIFF_WIDTH		INT32_WIDTH
+#define SIG_ATOMIC_WIDTH	INT32_WIDTH
+#define SIZE_WIDTH		INT32_WIDTH
+#endif
+#define WCHAR_WIDTH		INT32_WIDTH
+#define WINT_WIDTH		INT32_WIDTH
+#endif /* __ISO_C_VISIBLE >= 2023 */
+
 #endif /* !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) */
 
 #endif /* !_MACHINE__STDINT_H_ */
diff --git a/sys/riscv/include/_stdint.h b/sys/riscv/include/_stdint.h
index 4e032c8b0a1d..9df000b0eac4 100644
--- a/sys/riscv/include/_stdint.h
+++ b/sys/riscv/include/_stdint.h
@@ -151,6 +151,29 @@
 #define	WINT_MIN	INT32_MIN
 #define	WINT_MAX	INT32_MAX
 
+#if __ISO_C_VISIBLE >= 2023
+/*
+ * ISO/IEC 9899:2023
+ * 7.22.2 Widths of specified-width integer types
+ */
+#define INT_FAST8_WIDTH		INT32_WIDTH
+#define INT_FAST16_WIDTH	INT32_WIDTH
+#define INT_FAST32_WIDTH	INT32_WIDTH
+#define INT_FAST64_WIDTH	INT64_WIDTH
+#define INTPTR_WIDTH		INT64_WIDTH
+#define INTMAX_WIDTH		INT64_WIDTH
+
+/*
+ * ISO/IEC 9899:2023
+ * 7.22.3 Width of other integer types
+ */
+#define PTRDIFF_WIDTH		INT64_WIDTH
+#define SIG_ATOMIC_WIDTH	INT64_WIDTH
+#define SIZE_WIDTH		INT64_WIDTH
+#define WCHAR_WIDTH		INT32_WIDTH
+#define WINT_WIDTH		INT32_WIDTH
+#endif /* __ISO_C_VISIBLE >= 2023 */
+
 #endif /* !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) */
 
 #endif /* !_MACHINE__STDINT_H_ */
diff --git a/sys/sys/stdint.h b/sys/sys/stdint.h
index f82e391c9e41..77f469f3c2a3 100644
--- a/sys/sys/stdint.h
+++ b/sys/sys/stdint.h
@@ -73,4 +73,33 @@ typedef	__uint_fast64_t		uint_fast64_t;
 #endif
 #endif /* __EXT1_VISIBLE */
 
+#if __ISO_C_VISIBLE >= 2023
+#define INT8_WIDTH		8
+#define UINT8_WIDTH		8
+#define INT_LEAST8_WIDTH	8
+#define UINT_LEAST8_WIDTH	8
+#define UINT_FAST8_WIDTH	INT_FAST8_WIDTH
+
+#define INT16_WIDTH		16
+#define UINT16_WIDTH		16
+#define INT_LEAST16_WIDTH	16
+#define UINT_LEAST16_WIDTH	16
+#define UINT_FAST16_WIDTH	INT_FAST16_WIDTH
+
+#define INT32_WIDTH		32
+#define UINT32_WIDTH		32
+#define INT_LEAST32_WIDTH	32
+#define UINT_LEAST32_WIDTH	32
+#define UINT_FAST32_WIDTH	INT_FAST32_WIDTH
+
+#define INT64_WIDTH		64
+#define UINT64_WIDTH		64
+#define INT_LEAST64_WIDTH	64
+#define UINT_LEAST64_WIDTH	64
+#define UINT_FAST64_WIDTH	INT_FAST64_WIDTH
+
+#define	UINTMAX_WIDTH		INTMAX_WIDTH
+#define	UINTPTR_WIDTH		INTPTR_WIDTH
+#endif /* __ISO_C_VISIBLE >= 2023 */
+
 #endif /* !_SYS_STDINT_H_ */
diff --git a/sys/x86/include/_stdint.h b/sys/x86/include/_stdint.h
index 59aab4b39c0c..1b8523bf656b 100644
--- a/sys/x86/include/_stdint.h
+++ b/sys/x86/include/_stdint.h
@@ -184,6 +184,39 @@
 #define	WINT_MIN	INT32_MIN
 #define	WINT_MAX	INT32_MAX
 
+#if __ISO_C_VISIBLE >= 2023
+/*
+ * ISO/IEC 9899:2023
+ * 7.22.2 Widths of specified-width integer types
+ */
+#define INT_FAST8_WIDTH		INT32_WIDTH
+#define INT_FAST16_WIDTH	INT32_WIDTH
+#define INT_FAST32_WIDTH	INT32_WIDTH
+#define INT_FAST64_WIDTH	INT64_WIDTH
+#ifdef __LP64__
+#define INTPTR_WIDTH		INT64_WIDTH
+#else
+#define INTPTR_WIDTH		INT32_WIDTH
+#endif
+#define INTMAX_WIDTH		INT64_WIDTH
+
+/*
+ * ISO/IEC 9899:2023
+ * 7.22.3 Width of other integer types
+ */
+#ifdef	__LP64__
+#define PTRDIFF_WIDTH		INT64_WIDTH
+#define SIG_ATOMIC_WIDTH	INT64_WIDTH
+#define SIZE_WIDTH		INT64_WIDTH
+#else
+#define PTRDIFF_WIDTH		INT32_WIDTH
+#define SIG_ATOMIC_WIDTH	INT32_WIDTH
+#define SIZE_WIDTH		INT32_WIDTH
+#endif
+#define WCHAR_WIDTH		INT32_WIDTH
+#define WINT_WIDTH		INT32_WIDTH
+#endif /* __ISO_C_VISIBLE >= 2023 */
+
 #endif /* !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) */
 
 #endif /* !_MACHINE__STDINT_H_ */


help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?692c9961.26e23.67d8f161>