简体   繁体   中英

Difference between *f and (*f) in C?

CppCheck (v1.72) says there is a difference when using (*f) or just *f . The this case

void test(float *f)
{
    float a = 0.0f;
    if(*f>a)
    {
        (*f) += 0.01f;
        if(*f<a) *f=a;
    }
}

cppCheck says "Opposite conditions in nested 'if' blocks lead to a dead code block, where as

void test(float *f)
{
    float a = 0.0f;
    if(*f>a)
    {
        *f += 0.01f;
        if(*f<a) *f=a;
    }
}

makes cppCheck happy. What exactly is the difference?

There's no difference. Ideally, cppcheck should be warning you in both cases, because your code isn't logical.

However, cppcheck isn't infallible. Don't assume that if cppcheck shows no issues, there aren't any. It's just another useful tool that helps spot bad code that might otherwise go undetected.

Thank you for reporting this issue here on stackoverflow. I have created a ticket about this issue on cppcheck's bug tracker .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM