new file mode 100644
@@ -0,0 +1,47 @@
+/*
+ * Newlib specific addition to ensure the C23 *_WIDTH constants
+ * used in the stdbits implementation are available even when
+ * compiling using another version of the C Programming Language.
+ */
+
+/*
+ * Written by Joel Sherrill <joel.sherrill@OARcorp.com>.
+ *
+ * COPYRIGHT (c) 2026.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose without fee is hereby granted, provided that this entire notice
+ * is included in all copies of any software which is or includes a copy
+ * or modification of this software.
+ *
+ * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
+ * WARRANTY. IN PARTICULAR, THE AUTHOR MAKES NO REPRESENTATION
+ * OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS
+ * SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
+ */
+
+#ifndef STDBIT_INTERNAL_h
+#define STDBIT_INTERNAL_h
+
+#ifndef UCHAR_WIDTH
+#define UCHAR_WIDTH __SCHAR_WIDTH__
+#endif
+
+#ifndef USHRT_WIDTH
+#define USHRT_WIDTH __SHRT_WIDTH__
+#endif
+
+#ifndef UINT_WIDTH
+#define UINT_WIDTH __INT_WIDTH__
+#endif
+
+#ifndef ULONG_WIDTH
+#define ULONG_WIDTH __LONG_LONG_WIDTH__
+#endif
+
+#ifndef ULLONG_WIDTH
+#define ULLONG_WIDTH __LONG_LONG_WIDTH__
+#endif
+
+#endif
@@ -8,8 +8,10 @@
#include <limits.h>
#include <stdbit.h>
+#include "stdbit_internal.h"
+
/* Ensure we don't shift 1U out of range. */
-static_assert(UCHAR_WIDTH < UINT_WIDTH,
+_Static_assert(UCHAR_WIDTH < UINT_WIDTH,
"stdc_bit_ceil_uc needs UCHAR_WIDTH < UINT_WIDTH");
unsigned char
@@ -22,7 +24,7 @@ stdc_bit_ceil_uc(unsigned char x)
}
/* Ensure we don't shift 1U out of range. */
-static_assert(USHRT_WIDTH < UINT_WIDTH,
+_Static_assert(USHRT_WIDTH < UINT_WIDTH,
"stdc_bit_ceil_us needs USHRT_WIDTH < UINT_WIDTH");
unsigned short
@@ -7,6 +7,8 @@
#include <limits.h>
#include <stdbit.h>
+#include "stdbit_internal.h"
+
unsigned char
stdc_bit_floor_uc(unsigned char x)
{
@@ -7,6 +7,8 @@
#include <limits.h>
#include <stdbit.h>
+#include "stdbit_internal.h"
+
unsigned int
stdc_bit_width_uc(unsigned char x)
{
@@ -7,6 +7,8 @@
#include <limits.h>
#include <stdbit.h>
+#include "stdbit_internal.h"
+
unsigned int
stdc_count_ones_uc(unsigned char x)
{
@@ -7,6 +7,8 @@
#include <limits.h>
#include <stdbit.h>
+#include "stdbit_internal.h"
+
unsigned int
stdc_count_zeros_uc(unsigned char x)
{
@@ -7,6 +7,8 @@
#include <limits.h>
#include <stdbit.h>
+#include "stdbit_internal.h"
+
unsigned int
stdc_first_leading_one_uc(unsigned char x)
{
@@ -7,6 +7,8 @@
#include <limits.h>
#include <stdbit.h>
+#include "stdbit_internal.h"
+
unsigned int
stdc_first_leading_zero_uc(unsigned char x)
{
@@ -6,6 +6,8 @@
#include <stdbit.h>
+#include "stdbit_internal.h"
+
unsigned int
stdc_first_trailing_one_uc(unsigned char x)
{
@@ -7,6 +7,8 @@
#include <limits.h>
#include <stdbit.h>
+#include "stdbit_internal.h"
+
unsigned int
stdc_first_trailing_zero_uc(unsigned char x)
{
@@ -7,6 +7,8 @@
#include <stdbit.h>
#include <stdbool.h>
+#include "stdbit_internal.h"
+
bool
stdc_has_single_bit_uc(unsigned char x)
{
@@ -8,8 +8,10 @@
#include <limits.h>
#include <stdbit.h>
+#include "stdbit_internal.h"
+
/* Avoid triggering undefined behavior if x == 0. */
-static_assert(UCHAR_WIDTH < UINT_WIDTH,
+_Static_assert(UCHAR_WIDTH < UINT_WIDTH,
"stdc_leading_ones_uc needs UCHAR_WIDTH < UINT_WIDTH");
unsigned int
@@ -21,7 +23,7 @@ stdc_leading_ones_uc(unsigned char x)
}
/* Avoid triggering undefined behavior if x == 0. */
-static_assert(USHRT_WIDTH < UINT_WIDTH,
+_Static_assert(USHRT_WIDTH < UINT_WIDTH,
"stdc_leading_ones_us needs USHRT_WIDTH < UINT_WIDTH");
unsigned int
@@ -8,8 +8,10 @@
#include <limits.h>
#include <stdbit.h>
+#include "stdbit_internal.h"
+
/* Offset must be greater than zero. */
-static_assert(UCHAR_WIDTH < UINT_WIDTH,
+_Static_assert(UCHAR_WIDTH < UINT_WIDTH,
"stdc_leading_zeros_uc needs UCHAR_WIDTH < UINT_WIDTH");
unsigned int
@@ -21,7 +23,7 @@ stdc_leading_zeros_uc(unsigned char x)
}
/* Offset must be greater than zero. */
-static_assert(USHRT_WIDTH < UINT_WIDTH,
+_Static_assert(USHRT_WIDTH < UINT_WIDTH,
"stdc_leading_zeros_us needs USHRT_WIDTH < UINT_WIDTH");
unsigned int
@@ -8,8 +8,10 @@
#include <limits.h>
#include <stdbit.h>
+#include "stdbit_internal.h"
+
/* Avoid triggering undefined behavior if x == ~0. */
-static_assert(UCHAR_WIDTH < UINT_WIDTH,
+_Static_assert(UCHAR_WIDTH < UINT_WIDTH,
"stdc_trailing_ones_uc needs UCHAR_WIDTH < UINT_WIDTH");
unsigned int
@@ -19,7 +21,7 @@ stdc_trailing_ones_uc(unsigned char x)
}
/* Avoid triggering undefined behavior if x == ~0. */
-static_assert(USHRT_WIDTH < UINT_WIDTH,
+_Static_assert(USHRT_WIDTH < UINT_WIDTH,
"stdc_trailing_ones_uc needs USHRT_WIDTH < UINT_WIDTH");
unsigned int
@@ -8,8 +8,10 @@
#include <limits.h>
#include <stdbit.h>
+#include "stdbit_internal.h"
+
/* Ensure we do not shift 1U out of range. */
-static_assert(UCHAR_WIDTH < UINT_WIDTH,
+_Static_assert(UCHAR_WIDTH < UINT_WIDTH,
"stdc_trailing_zeros_uc needs UCHAR_WIDTH < UINT_WIDTH");
unsigned int
@@ -19,7 +21,7 @@ stdc_trailing_zeros_uc(unsigned char x)
}
/* Ensure we do not shift 1U out of range. */
-static_assert(USHRT_WIDTH < UINT_WIDTH,
+_Static_assert(USHRT_WIDTH < UINT_WIDTH,
"stdc_trailing_zeros_uc needs USHRT_WIDTH < UINT_WIDTH");
unsigned int