c++ - "return"关键字之后的语句会被执行吗?

标签 c++ visual-c++ return

我是C++初学者,想知道这种情况的影响:

PCONSOLE_SCREEN_BUFFER_INFOEX GetConsoleInfo(void) {
    WaitForSingleObject(m_hSync);   // m_hSync is HANDLE to mutex created using CreateMutex()

    return m_pcsbi;    // m_pcsbi is of type PCONSOLE_SCREEN_BUFFER_INFOEX

    ReleaseMutex(m_hSync);      // <== will this line be executed?
}

不知道 [ReleaseMutex()] 会被执行吗?

最佳答案

在您的情况下,无法获取该代码。如果您有条件 return(例如 if (ptr==nullptr) return; ),那么当然会有跳过 return 的条件。但是无条件返回将是最后执行的语句。

然而,RAII return 之后会进行样式清理。

关于c++ - "return"关键字之后的语句会被执行吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23102194/

相关文章:

c++ - WindowsIdentity.GetCurrent().C++ 中的 IsSystem

c++ - 如何枚举已分配指定用户权限的所有 SID? C++

c++ - 忙于轮询 std::atomic - msvc 优化了循环 - 为什么以及如何防止?

c# - 将 C# 代码转换为 C++ : Hex to Binary

linux - 映射到给定键盘快捷键的 linux shell 命令的名称?

c++ - 错误 : Element <EnableEnhancedInstructionSet> has an invalid value of "NoExtensions"

c++ - 构建 std::function 的 vector 时出现编译器错误

visual-c++ - 为 Windows Phone 8 C++/CX 创建 HTTP 请求

c++ - 函数怎么写才整齐?考虑日志,一次返回,不再缩进?

Python - 为什么 __str__ 在调用时想要返回一些东西?我在 __str__ 中有打印函数