added macros for printf format codes

This commit is contained in:
2025-11-15 12:12:06 +05:00
parent 5ef223372b
commit ae0fa95d6a
5 changed files with 49 additions and 16 deletions

View File

@@ -7,21 +7,23 @@ extern "C" {
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <stddef.h>
#include <string.h>
#include <stdarg.h>
#include <errno.h>
typedef int8_t i8;
typedef uint8_t u8;
typedef int16_t i16;
typedef uint16_t u16;
typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef float f32;
typedef double f64;
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;
typedef float f32;
typedef double f64;
typedef const char* cstr;
#if !__cplusplus && !defined(bool)
typedef u8 bool;
@@ -29,7 +31,29 @@ typedef u8 bool;
#define false 0
#endif
typedef const char* cstr;
#define FMT_i8 "%"PRIi8
#define FMT_i16 "%"PRIi16
#define FMT_i32 "%"PRIi32
#define FMT_i64 "%"PRIi64
#define FMT_u8 "%"PRIu8
#define FMT_u16 "%"PRIu16
#define FMT_u32 "%"PRIu32
#define FMT_u64 "%"PRIu64
#define FMT_x8 "%"PRIx8
#define FMT_x16 "%"PRIx16
#define FMT_x32 "%"PRIx32
#define FMT_x64 "%"PRIx64
#define FMT_X8 "%"PRIX8
#define FMT_X16 "%"PRIX16
#define FMT_X32 "%"PRIX32
#define FMT_X64 "%"PRIX64
#define FMT_o8 "%"PRIo8
#define FMT_o16 "%"PRIo16
#define FMT_o32 "%"PRIo32
#define FMT_o64 "%"PRIo64
#define FMT_f32 "%f"
#define FMT_f64 "%lf"
#define dbg(N) printf("\e[95m%d\n",N)

View File

@@ -30,6 +30,7 @@ void StringBuilder_append_cstr(StringBuilder* b, cstr s);
void StringBuilder_append_str(StringBuilder* b, str s);
void StringBuilder_append_i64(StringBuilder* b, i64 a);
void StringBuilder_append_u64(StringBuilder* b, u64 a);
void StringBuilder_append_f32(StringBuilder* b, f32 n);
void StringBuilder_append_f64(StringBuilder* b, f64 a);
void StringBuilder_append_memory(StringBuilder* b, Array(u8) mem, bool uppercase);

View File

@@ -11,6 +11,8 @@ typedef struct str {
bool isZeroTerminated;
} str;
#define FMT_str "%.*s"
/// creates str from a string literal
#define STR(LITERAL) str_construct(LITERAL, ARRAY_LEN(LITERAL) - 1, true)