GithubHelp home page GithubHelp logo

gymadarasz / c-callstack Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nanolat/c-callstack

0.0 2.0 0.0 192 KB

An implementation to show Java-like call stack in C/C++ code.

License: Apache License 2.0

Makefile 9.79% C 90.21%

c-callstack's Introduction

c-callstack

An implementation to show Java-like call stack in C/C++ code.

Problem

Usually C programmers use int type for the return value of a function, returning a non-zero value indicating that an error has happened in it. However, with tens of nested function calls, it is takes time to know where the error happened at the beginning.

int foo(...)
{
    if (error happened)
        return -1;
    
    ... do something ...

    return 0
}

Solution

Include c-callstack.h. Use NL_RETURN(x) instead of return x in your source code.

#include "c-callstack.h"

int foo(...)
{
    if (error happened)
        NL_RETURN(-1);
    
    ... do something ...

    NL_RETURN(0);
}

Example Call Stack

Make it, and run ./sample. You will see pretty call stack in your C/C++ program.

kangmo@ubuntu:~/c-callstack$ make
gcc -g -O0 sample.c -o sample

kangmo@ubuntu:~/c-callstack$ ./sample 
If you love me, you are in trouble, as I am married.
Error(code:-1) at : so_topless_ranking_server (sample.c:23)
Error(code:-1) at : nanolat_database (sample.c:31)
Error(code:-1) at : nanolat_message_queue (sample.c:39)
Error(code:-1) at : main (sample.c:47)

kangmo@ubuntu:~/c-callstack$ 

License

The source code is released under Apache v2 license. Use it as you wish, but it would be great if you can buy a bottle of beer when you meet me!

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.