开发者

Debugger ignores me

开发者 https://www.devze.com 2022-12-25 08:54 出处:网络
Having code: Date::Date(cons开发者_JAVA技巧t char* day, const char* month, const char* year):is_leap__(false)

Having code:

Date::Date(cons开发者_JAVA技巧t 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;
    }
}

Which is very strange in my opinion. There is call to this fnc in my code, why compiler ignores that.

P.S. I'm trying to debug in release.


Trying to debug in release leads to pain. The function is being inlined, so you can't break on it. This kind of optimization will happen everywhere, values in variables will seem off, etc. Best to debug in debug.

By the way, just do: return !(year%400) || (year%100 && !(year%4));


What I mean by "it got inlined" is that your code, at that part, became:

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

There is no function call, and nothing to break on.


A function header does indeed not compile to any executable code. Try setting the breakpoint on the open brace, or the first statement in the function.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号