In OpenGL superbible 4th ed, an example on pg 70 reads
//returns space-delimited names of all extensions supported by the OpenGLDriver
const char *extensions = glGetString(GL_EXTENSIONS);
if(strstr(extensions, "WGL_EXT_swap_control" != NULL))
{
//...
}
Is this a type-o? Or am I missing an #include? I can’t find an overload for strstr() to support this call. I think it should be
if(strstr(extensions, "WGL_EXT_swap_control") != NULL)
{
//...
}
Yes, obvious typo. Your code is correct. C does not support overloading.
The prototype of the function would have to be
int strstr(const char *s, int h);for the book’s code to compile, and that doesn’t (as Jonathon Reinhart sort of pointed out) make a lot of sense; how do you look for an integer in a string?UPDATE: There’s a lesson here about the quality feel from books whose “example” code obviously won’t compile.
UPDATE 2: As forsvarir points out, you can get a C compiler to compile this, in which case it will treat the integer resulting from the comparison as a string pointer regardless, and run
strstr()using that. Which, on many operating systems, will immediately crash, and which will invoke undefined behavior on all systems.