-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Printing of nullptr (char const * and void *) #226
Comments
Passing a null string to const char *s = 0;
std::printf("%s\n", s); // segfaults in glibc while the result of pointer formatting is implementation-defined. That said, I think it's reasonable to expect Thanks! |
Super.
is not glibc. Gcc has optimized away the whole printf and just does a puts The code I used to create the small table in OP is:
|
Right, this is a GCC's "optimization" (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25609), not glibc's behavior. |
When using cppformat as a drop-in replacement for printf on Linux with GLibc the behavior
of printing nullptr changes quite radically:
I would be really nice if the behaviour was kept. Esp. not throwing on Null-string. Perhaps it
would even be possible to retain the behaviour from whatever platform you were on.
I have done some of this in my cppformat copy, but perhaps a bit too broad since I also do this for fmt::format (not as you would want it most likely):
The text was updated successfully, but these errors were encountered: