Giter Club home page Giter Club logo

debug's Introduction

Debugging like a sir (in C)

#include "debug.h"

int answer(void) {
    return 42;
}

int main(void) {

    int num = 1;
    char *str = "hello";

    debug(num);
    // => num = 1

    debug(num, str, answer());
    // => num = 1
    //    str = hello
    //    answer() = 42

    debug_raw("counting:", 1, -2, 3 + 0.4);
    // => counting: 1 -2 3.4

    debug_raw(str, "world!");
    // => hello world!

    idebug(num);
    // => example.c:26: num = 1

    idebug(num, str);
    // => example.c:29:
    //            num = 1
    //            str = hello

    idebug_raw("The answer is", answer());
    // => example.c:34: The answer is 42

    return 0;
}

Usage

Just include debug.h in your file.

Gotchas

  • Requires C11 support (uses _Generic). Consider using the flag -std=c11 when compiling.
  • Literal chars have type int, so you have to cast them to char to print them as actual chars:
debug_raw("Find the", (char)'X'); // => Find the X

Tips

For quick debugging, include the header right where you need it:

void function(void) {
    ...
    #include "debug.h"
    debug(var); // => var = XXX
    ...
}

To remove quickly all debugging output, define NDEBUG before the header inclusion:

#define NDEBUG
#include "debug.h"
...
debug(var); // Doesn't print anything
...

debug's People

Contributors

esneider avatar xiechao06 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.