Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cgkantidis/cpp_dbg_out
A dbg_out variadic macro that prints the function, file, line and the rest of the arguments from where it's called, to the standard output.
https://github.com/cgkantidis/cpp_dbg_out
cpp debug variadic-function variadic-macro
Last synced: about 2 months ago
JSON representation
A dbg_out variadic macro that prints the function, file, line and the rest of the arguments from where it's called, to the standard output.
- Host: GitHub
- URL: https://github.com/cgkantidis/cpp_dbg_out
- Owner: cgkantidis
- Created: 2022-11-06T21:57:35.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2022-12-01T00:24:44.000Z (about 2 years ago)
- Last Synced: 2024-11-25T16:14:26.340Z (about 2 months ago)
- Topics: cpp, debug, variadic-function, variadic-macro
- Language: CMake
- Homepage:
- Size: 18.6 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## cpp_dbg_out
A `dbg_out` [variadic macro](https://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html) that prints the function, file, line and the rest of the arguments from where it's called, to the standard output.The developer can enable the debug messages by defining `ENABLE_DBG_OUT`, and change the call to a no-op by not defining `ENABLE_DBG_OUT`.
It is thread-safe to call this macro from multiple threads.
It works both in gcc and clang, and requires C++17.
## Compile and run
```bash
cmake -S . -B build
cmake --build build
./build/main
```So this call inside main(), in the main.cpp file at line 29
```cpp
dbg_out("Hello", "World", 3);
```Will print:
```
main main.cpp:29 Hello World 3
```## Disable the `dbg_out`
To disable the printing of the debug messages, just comment out the
```cpp
#define ENABLE_DBG_OUT
```The definition of `ENABLE_DBG_OUT` can also be done from the terminal, by adding the `-DENABLE_DBG_OUT` compilation option.