Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

coding style aginst warning check

During clean compile warning, I met following code:

char *strcpy(char *dest, char *src)
{
    unsigned int i;

    while( dest[i] = src[i] )//assignment in condition
        i++;

    return dest;
}

the base function of the code should be OK, but compiler warn that the assignment in condition, does this part of code have any potential risks? if this kind of warning need be cleaned?

like image 904
How Chen Avatar asked Feb 06 '26 01:02

How Chen


1 Answers

All kinds of warnings need to be cleaned.

This warning was introduced because = and == is often confused by programmers (hello, Pascal!), and your intent may be explicitly stated by adding parentheses around assignment expression:

if ((x = y)) // no warning
like image 189
user3125367 Avatar answered Feb 07 '26 13:02

user3125367



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!