Here you sets the badbit
on the stream which causes nothing to be printed after cout<<(char*)NULL;
if (!__s)
__out.setstate(ios_base::badbit);
The standard says: requires: shall not be a null pointer
. So your program definitely has the undefined behavior and it should be fixed. You can clear the bad bit by using cout.clear()
.
In your case, cout<<(char*)NULL;
causes undefined behavior. But GCC plays it safely.
Hope this helps!