C Get function line number from within 2 function calls

In the process of developing a small SDK, I need to create an “error handler”. To make more effective I want to get the line number where the function was called and I don’t know if it’s possible in C (using GCC for compiling).

When a SDK function is called, the SDK function itself will call the error handler function if an error occurred.

With that I’d like to know if there is a way to know the line number from the user source code that called the function.

Example :

User.c :

main{ void = CallSDKFunction(); }

SDK.a file :

void CallSDKFunction(){ if ( ERROR ){ CallERRORHandler(); } }
...
...

void CallERRORHandler(){ // Here I want to know in which line in user.c the CallSDKFunction was called}


Source: gcc

Leave a Reply