Skip to content

Instantly share code, notes, and snippets.

@benjamin051000
Last active February 24, 2023 17:56
Show Gist options
  • Save benjamin051000/6d2a8e194e975dfc73450c3c0665a8ef to your computer and use it in GitHub Desktop.
Save benjamin051000/6d2a8e194e975dfc73450c3c0665a8ef to your computer and use it in GitHub Desktop.
Some useful tools I use when I write C to make it a little nicer
/**
* c-tools.h
*
* My collection of useful stuff that C doesn't come with
*/
#ifdef RUSTY_INT_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;
#endif
// Use via `#define DEBUG`
#ifdef DEBUG
#define DBG(x) x
// Awesome printf wrapper, similar to Rust's `dbg!()` macro.
// It looks something like this:
// [src/main.c:123] printed stuff
#define DP(x, ...) (printf("[%s:%d] ", __FILE__, __LINE__), printf(x, __VA_ARGS__))
#else
#define DBG(x)
#define DP(x)
#endif
// Use via `#define RELEASE`
#ifdef RELEASE_
#define RELEASE(x) x
#else
#define RELEASE(x)
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment