Search code examples
cruntime-errorline-numbers

Is there any way to get the source code line number in C code in run time?


Is there any way to get the source code line number in C code in run time? The thought behind it is, suppose a software is made in plain C language. the .exe file is distributed to a user who knows nothing about C. Now if there is any error, the user can see the line number and report the error to the manufacturer so that the debugging can be done at manufacturer site. I just to debug the run time errors and get the corresponding line numbers in the source code while running it. I am a beginner in these stuffs.


Solution

  • Use gdb instead. But I guess it will work:

      if(someThingsWrong())
        printf("wrong at line number %d in file %s\n", __LINE__, __FILE__);