c++ - 调试器不理我

标签 c++ reverse-debugging

有代码:

Date::Date(const char* day, const char* month, const char* year):is_leap__(false)
{
    my_day_ = lexical_cast<int>(day);


    my_month_ = static_cast<Month>(lexical_cast<int>(month));

    /*Have to check month here, other ctor assumes month is correct*/
    if (my_month_ < 1 || my_month_ > 12)
    {
        throw std::exception("Incorrect month.");
    }
    my_year_ = lexical_cast<int>(year);

    if (!check_range_year_(my_year_))
    {
        throw std::exception("Year out of range.");
    }

    if (check_leap_year_(my_year_))//SKIPS THIS LINE
    {
        is_leap__ = true;
    }
    if (!check_range_day_(my_day_, my_month_))
    {
        throw std::exception("Day out of range.");
    }

}

bool Date::check_leap_year_(int year)const//IF I MARK THIS LINE WITH BREAKPOINT I'M GETTING MSG THAT THERE IS NO EXECUTABLE CODE IS ASSOSIATED WITH THIS LINE
{
    if (!(year%400) || (year%100 && !(year%4)))
    {
        return true;
    }
    else
    {
        return false;
    }
}

我觉得这很奇怪。在我的代码中调用了这个 fnc,为什么编译器会忽略它。
附言我正在尝试在发布中进行调试。

最佳答案

尝试在发布中调试会导致痛苦。该函数正在内联,因此您无法中断它。这种优化无处不在,变量中的值看起来不对等。最好在调试中调试。

顺便说一句,只要做:return !(year%400) || (年%100 && !(年%4));


我所说的“内联”是指您的代码在那部分变成了:

if (!(my_year_%400) || (my_year_%100 && !(my_year_%4)))
{
    is_leap__ = true;
}

没有函数调用,也没有什么可以中断的。

关于c++ - 调试器不理我,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2574864/

相关文章:

c++ - Visual Studio 2008 中的 POD

c++ - 使用关闭按钮关闭 Opencv 窗口

debugging - ReplayDIRECTOR/Chronon Debugger 是否有任何开源替代品?

Java 和 C++ (VS) RSA 加密

c++ - 如何在 QTextEdit 中设置自定义文本颜色?

c++ - 如何生成vcproj文件?

debugging - 我可以在核心转储文件中使用 "Reverse Debugging"吗?

reverse-debugging - 逆向调试如何进行?

visual-studio-2013 - 我可以获得 Visual Studio 2013 Professional 的反向调试功能吗?

gdb - 有人尝试过在 gdb 中进行反向调试吗?