That's interesting. I can indeed pass a NULL to printf() and it prints out "(null)" but when I pass an empty, dynamic string I get a sefault:dkl wrote:I don't really see a problem, maybe a small inconsistency at best...
Printing *myStringPtr or *myZstringPtr will call the Print function and pass the string Byref, and as it happens, it checks for NULL, and prints nothing in that case. That's a pretty good way of dealing with that problem, don't you think? Alternatively it could crash, or print something like "(null)" like some CRTs' printf() does. But that seems worse to me than printing nothing.
Code: Select all
#include "crt.bi"
dim as zstring ptr b
dim as string g
b = 0
printf(!"%s\n",b)
printf(!"%s\n",g)
I'm not convinced printing nothing for a null pointer is the best way of dealing with the problem. If you're trying to print out a string that's really a null pointer, that's likely an error in your code somewhere, one that is hidden until it finally blows up in some C library.
EDIT. I see why it segfaults. There is a dereference in the C code emitted by the computer, before it even gets to printf.