john
john

Reputation: 147

using nullptr instead of NULL when mixing C and C++

i have a very simple question...

i am using the SDL API which was written in C. i am using C++. my compiler supports the keyword nullptr, and I've been reading up on it. it seems as if it is better to use rather than using the NULL macro.

when I call SDL_SetVideoMode, I assume it returns NULL on failure, so if i do:

SDL_Surface *test = nullptr;

if ((test = SDL_SetVideoMode(params)) == nullptr)
{
    // to-do code
}

will this accurately check if my optimization on the surface test was successful?

Upvotes: 11

Views: 1636

Answers (1)

Kyle Jones
Kyle Jones

Reputation: 5532

Yes. nullptr is comparable to and equivalent to a null pointer of any other pointer type.

Upvotes: 13

Related Questions