summaryrefslogtreecommitdiff
path: root/include/u8c/SIZE_C.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/u8c/SIZE_C.h')
-rw-r--r--include/u8c/SIZE_C.h21
1 files changed, 11 insertions, 10 deletions
diff --git a/include/u8c/SIZE_C.h b/include/u8c/SIZE_C.h
index 7c9d1a9..1591252 100644
--- a/include/u8c/SIZE_C.h
+++ b/include/u8c/SIZE_C.h
@@ -14,17 +14,13 @@
If not, see <https://www.gnu.org/licenses/>.
*/
/* Size constant */
-# if !defined SIZE_C
+# if !defined(SIZE_C)
+# if !defined(__cplusplus)
# include <limits.h>
-# include <stdint.h>
-# if SIZE_MAX == USHRT_MAX
-# if defined(__cplusplus)
-/* C++ : Use variable initialisation. */
-# define SIZE_C(val) (unsigned short{val})
-# else
-/* C : Use compound literal. */
-# define SIZE_C(val) ((unsigned short){val})
# endif
+# if defined(__cplusplus) && __cplusplus > 0x31512l
+/* C++23 has a size_t suffix. */
+# define SIZE_C(val) val ## uz
# elif SIZE_MAX == UINT_MAX
# define SIZE_C(val) val
# elif SIZE_MAX == ULONG_MAX
@@ -32,12 +28,17 @@
# elif SIZE_MAX == ULLONG_MAX
# define SIZE_C(val) val ## ull
# elif SIZE_MAX == UINTMAX_MAX
-# define SIZE_C(val) UINTMAX_C(val)
+# include <stdint.h>
+# define SIZE_C(val) (UINTMAX_C(val))
# else
/* Cannot match width; construct new element of type "size_t" */
# if defined(__cplusplus)
+/* C++ has value initialisation. */
+# include <cstddef>
# define SIZE_C(val) (std::size_t{val})
# else
+/* C has compound literals. */
+# include <stddef.h>
# define SIZE_C(val) ((size_t){val})
# endif
# endif