Skip to content

Instantly share code, notes, and snippets.

@petewarden
Created February 15, 2022 19:12
Show Gist options
  • Save petewarden/b6a4c471b84e4a80712d832124b6138b to your computer and use it in GitHub Desktop.
Save petewarden/b6a4c471b84e4a80712d832124b6138b to your computer and use it in GitHub Desktop.
Header file for simple variable tracing macros
#ifndef INCLUDE_TRACE_H
#define INCLUDE_TRACE_H
#include <stdio.h>
#include <stdint.h>
#define TRACE_STR(variable) do { fprintf(stderr, __FILE__":%d "#variable"=%s\n", __LINE__, variable); } while (0)
#define TRACE_INT(variable) do { fprintf(stderr, __FILE__":%d "#variable"=%d\n", __LINE__, variable); } while (0)
#define TRACE_PTR(variable) do { fprintf(stderr, __FILE__":%d "#variable"=0x%016lx\n", __LINE__, (uint64_t)(variable)); } while (0)
#define TRACE_SIZ(variable) do { fprintf(stderr, __FILE__":%d "#variable"=%zu\n", __LINE__, variable); } while (0)
#endif // INCLUDE_TRACE_H
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment