It took me a while to figure out why some cout output seem to disappear into the ether. The culprit:
std::cout<< "This line shows up just fine" << std::endl;
const char* some_string = a_function_that_returns_null();
if (some_string == 0)
std::cout<< "Let's check the value of some_string: " << some_string << std::endl;
std::cout<< "This line and any cout output afterwards will not show up" << std::endl;
The output from the snippet above will be:
This line shows up just fine
Let's check the value of some_string:
So feeding a NULL into cout will disable all output afterward. Why? And how to fix it?
This doesn't happen all the time - a co-worker with the same code gets all the expected output. And in case you wonder why I can't just prevent feeding NULL into cout with a if statement: I'm working in a large codebase, and don't know where else this happens! All I know is the cout statements I put never showed up.
More info:
a_function_that_returns_null()
is actually getenv("HOST")
. I checked on the commandline via echo $HOST
that the HOST variable is empty. If I do export HOST=
(bash flavor), the output are all there. I have no idea what the HOST variable contains initially nor what getenv
returns initially when before I modify the HOST variable; all I know is (some_string == 0)
is true.