我有一个非常简单的问题......
我使用的是用C语言编写的SDL API.我正在使用C++.我的编译器支持关键字nullptr,我一直在阅读它.似乎使用而不是使用NULL宏更好.
当我调用SDL_SetVideoMode时,我假设它在失败时返回NULL,所以如果我这样做:
SDL_Surface *test = nullptr;
if ((test = SDL_SetVideoMode(params)) == nullptr)
{
// to-do code
}
Run Code Online (Sandbox Code Playgroud)
这会准确地检查我在表面测试中的优化是否成功?
这样的事情做什么?
static int i;
// wrapped in a big loop
void update_text()
{
std::stringstream ss; // this gets called again and again
++i;
ss << i;
text = new_text(ss.str()); // text and new_text are defined elsewhere
show_text(text); // so is this
}
Run Code Online (Sandbox Code Playgroud)
是用新地址和所有东西在堆栈中创建一个新的ss实例?将sprintf与char数组一起使用会更聪明吗?