[cfe-dev] What is the StringRef equivalent of NULL?

Bo Persson bop at gmb.dk
Wed Aug 18 00:40:58 PDT 2010




On 17 aug 2010 21:11 "Peter Davies" <ultratwo at gmail.com> wrote:
> > Because that constructor is specified to take a non-null pointer :).
> >  It is a hot method and doing the null check would be wasteful.
> >
> > -Chris
> 
> In the vast majority of cases (static argument), that cost will be
> eliminated by a decent optimizer. This makes converting functions
> that
> accept NULL in their const char * args hard to convert. Ultimately
> though, it's your choice.
> 
> Peter

I guess the argument here is the same as for std::string, that users who never ever pass null pointers see it as wasteful to have a test for every call. If someone believes his code can contain null pointers, the check could be before calling the constructor.

This is C++'s "you don't pay for what you don't use", to the extreme.


Bo Persson




More information about the cfe-dev mailing list