Sometimes, I'm doing some pretty plain mathy stuff, maybe in a tight loop (total nonsense pseudocode):
1
2
3
4
5
6
7
while(true)
{
int32_t x = i + 3 * b / 5;
int32_t y = x + 7 - j + 99;
float z = x * y + j;
... more math stuff
}


Here's what I want to do:
1
2
3
4
5
6
7
8
9
DEBUG_PRINTF
{
  while(true)
  {
    int32_t x = i + 3 * b / 5;
    int32_t y = x + 7 - j++ + 99;
    float z = x * y + j;
  }
}


And when I execute my program, I'll get something like this printed to stdout (these numbers are super nonsense, but ignore that):
1
2
3
4
main.cpp:5 - x:120 i:29 b:80
main.cpp:6 - y:700 j:12
main.cpp:7 - z:84013 y:700 j:13 
... more variable values from subsequent lines...


What I don't want to do:
  • Type a bunch of tedious printf statements (imagine the lines above had many more identifiers).
  • Step through code using a debugger (Because maybe I'm in release mode, or maybe this is a tight loop and I want to see the data change over long periods of time. Also, debuggers suck. Etc.

  • For now, I've actually built a little tool to do this for me in vim, and I used Allen's 4cpp to do it (Thanks!):
    https://github.com/AndrewJDR/aj_m...ster/cpp_print_all_ident_vals.cpp
    This tool takes a line of cpp code on its stdin, lexes it using 4cpp, then tries to output a cout line that will print the values of variables on the line.
    This is a poor-man's version of the feature, so while it's handy for my purposes, it's ultimately not the best solution. So I'm looking forward to seeing this in 4coder some day, maybe along with some metaprogramming magic sauce enabled by its parser :)

    It's also possible this will be solved with improved debuggers some day. But something tells me printf debugging will stick around for quite a while...