5 ms·
printf doesn't have undefined behavior on being passed null. printf("%p\n", (void *) 0); // not undefined It's the specific conversion specifier %s which do
by kazinator 11y ago
printf doesn't have undefined behavior on being passed null.
printf("%p\n", (void *) 0); // not undefined
It's the specific conversion specifier %s which doesn't have defined behavior.
> anything which can crash should crash
__asm__ __volatile__ can crash. It's undefined behavior.
- dbaupp 11y agoYou're 100% pedantically correct, passing a NULL pointer as the corresponding argument to %p is fine... But that's really missing the point, since we're discussing %s and the only sensible general interpretation of this discussion presumably includes a "(when the other arguments mean the NULL is actually UB)" on everything. (E.g. the assertion for non-NULL-ity would go on the branch of printf that handles %s.)