[ create a new paste ] login | about

Link: http://codepad.org/wducxbbJ    [ raw code | output | fork ]

AaronMiller - C, pasted on Oct 2:
#include <stdio.h>
#include <stdarg.h>

void debugf_int(const char *file, unsigned int line, const char *format, ...) {
  static char buf[8192];
  va_list args;

  va_start(args, format);
  vsnprintf(buf, sizeof(buf)-1, format, args);
  va_end(args);

  fprintf(stderr, "debug: %s:%u: %s\n", file, line, buf);
  fflush(stderr);
}
#define debugf(f,...) debugf_int(__FILE__, __LINE__, f, ##__VA_ARGS__)

int main() {
  debugf("Hello, world!");
  debugf("This is an integer: %d", 5);
  debugf("Here's more: %d, %.1f, \"%s\"", 42, 2.3f, "Hi!");

  return 0;
}


Output:
1
2
3
debug: t.c:19: Hello, world!
debug: t.c:20: This is an integer: 5
debug: t.c:21: Here's more: 42, 2.3, "Hi!"


Create a new paste based on this one


Comments: