Suppose that I tried to open a file but the file does not exist. I could check this with is_open()
or catch
an exception. But I would like to know in which function this action was attempted and on which line. If it is tricky to get line number, I am still OK with the function name. How can I do this?
Asked
Active
Viewed 234 times
0

Shibli
- 5,879
- 13
- 62
- 126
-
2This answer will fit your exact needs: http://stackoverflow.com/questions/597078/file-line-and-function-usage-in-c – Dominic Hofer Aug 26 '16 at 11:41
1 Answers
1
C99 introduces __func__, and GCC has provided __FUNCTION__ for a long time. Both of these are strings containing the name of the current function.
source: https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html

Krzysztof Bargieł
- 143
- 8