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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With