by jacobgorm · 3y ago · 0 comments
s/^$/printf("@%d\\n", __LINE__);
To place a line printf on every empty line in the program, to quickly find out where your code crashes on the next run.
Obviates most of my need for external debuggers, and works over serial lines etc where setting up a debugger is going to be a hassle or simply not possible.
Which I think is a good habit to have anyway. Some people use comments without preceding empty lines (oh why) to delineate code, so they'd have to change the regex a bit to make this work.
Would this be better?
s/^$/printf("@%d\\n", __LINE__);@
:s/.*/printf("& -- %d\\n", __LINE__); &
This only works on lines that don't have string literals and behaves badly on lines that span block boundaries.I had confused @ and &