Compare commits

...

2 Commits

Author SHA1 Message Date
ff7598a7e3 rework attributes to be a bit safer and more logical.
we are targeting GNU extensions, GNU attributes are a part of that.
added aliases for the new attribute names (name as all caps = shorter
due to `atrb_` prefix)
The aliases are likely to be removed in a later commit
2025-07-31 11:27:57 +02:00
e472d9c251 rename types.h to intdef.h and replace types.h with a symlink.
`intdef.h` is more clear in the purpose that it describes, rather than
`types`, `types` is too generic.
Note: floating points are still defined in this header, I imagine this
to be removed later, alongside the compatibility symlink.
2025-07-31 11:27:57 +02:00
3 changed files with 88 additions and 48 deletions

View File

@@ -2,29 +2,68 @@
// Licensed under the MIT Licence. See LICENSE for details // Licensed under the MIT Licence. See LICENSE for details
#pragma once #pragma once
// define the attributes where possible #if defined(__GNUC__)
#if defined(__GNUC__) || defined(__clang__) #if __has_attribute(__pure__)
#define atrb(...) __attribute__(__VA_ARGS__) #define PURE __attribute__((__pure__))
#define atrb_deprecated __attribute__((depricated))
#define atrb_unused __attribute__((unused))
#define atrb_pure __attribute__((pure))
#define atrb_const __attribute__((const))
#define atrb_noreturn __attribute__((noreturn))
#define atrb_malloc __attribute__((malloc))
#define atrb_format(...) __attribute__((format(__VA_ARGS__)))
#define atrb_nonnull(...) __attribute__((nonnull(__VA_ARGS__)))
#elif defined(_MSC_VER)
#define atrb(...) __declspec(__VA_ARGS__)
#define atrb_deprecated __declspec(deprecated)
#define atrb_noreturn __declspec(noreturn)
#else #else
#define atrb() #define PURE
#define atrb_deprecated
#define atrb_unused
#define atrb_pure
#define atrb_const
#define atrb_noreturn
#define atrb_malloc
#define atrb_format()
#define atrb_nonnull()
#endif #endif
#if __has_attribute(__const__)
#define CONST __attribute__((__const__))
#else
#define CONST
#endif
#if __has_attribute(__noreturn__)
#define NORET __attribute__((__noreturn__))
#else
#define NORET
#endif
#if __has_attribute(__malloc__)
#define MALLOC __attribute__((__malloc__))
#else
#define MALLOC
#endif
#if __has_attribute(__used__)
#define USED __attribute__((__used__))
#else
#define USED
#endif
#if __has_attribute(__unused__)
#define UNUSED __attribute__((__unused__))
#else
#define UNUSED
#endif
#if __has_attribute(__deprecated__)
#define DEPRECATED __attribute__((__deprecated__))
#else
#define DEPRECATED
#endif
#if __has_attribute(__format__)
#define FORMAT(...) __attribute__((format(__VA_ARGS__)))
#else
#define FORMAT(...)
#endif
#if __has_attribute(__nonnull__)
#define NONNULL(...) __attribute__((nonnull(__VA_ARGS__)))
#else
#define NONNULL(...)
#endif
#endif
#define atrb_deprecated DEPRECATED
#define atrb_used USED
#define atrb_unused UNUSED
#define atrb_pure PURE
#define atrb_const CONST
#define atrb_noreturn NORET
#define atrb_malloc MALLOC
#define atrb_format FORMAT
#define atrb_nonnull NONNULL

24
src/util/intdef.h Normal file
View File

@@ -0,0 +1,24 @@
// Copyright (c) 2025 Quinn
// Licensed under the MIT Licence. See LICENSE for details
#pragma once
/* variable-width integer types */
typedef unsigned int uint; // ≥16 bit unsigned integer
typedef unsigned long ulong; // ≥32 bit unsigned integer
typedef signed long long llong; // ≥64 bit signed integer
typedef unsigned long long ullong; // ≥64 bit unsigned integer
/* fixed-width integer types */
#include <stdint.h>
typedef int8_t i8;
typedef int16_t i16;
typedef int32_t i32;
typedef int64_t i64;
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
/* floating point types */
typedef float f32; // single-precision floating-point
typedef double f64; // double-precision floating-point

View File

@@ -1,24 +0,0 @@
// Copyright (c) 2025 Quinn
// Licensed under the MIT Licence. See LICENSE for details
#pragma once
/* variable-width integer types */
typedef unsigned int uint; // ≥16 bit unsigned integer
typedef unsigned long ulong; // ≥32 bit unsigned integer
typedef signed long long llong; // ≥64 bit signed integer
typedef unsigned long long ullong; // ≥64 bit unsigned integer
/* fixed-width integer types */
#include <stdint.h>
typedef int8_t i8;
typedef int16_t i16;
typedef int32_t i32;
typedef int64_t i64;
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
/* floating point types */
typedef float f32; // single-precision floating-point
typedef double f64; // double-precision floating-point

1
src/util/types.h Symbolic link
View File

@@ -0,0 +1 @@
intdef.h