I'm having hard time understanding nature of issue I encountered in my code. Line
if ((struct.c == 0x02) && (struct2.c == 0x02) && (struct.s == !struct2.s))
{/**/}
where c is int and s is uint64_t produces
C4388:'==' signed/unsigned mismatch
warning. I understand what that warning is, I can't see what is triggering it here. What am I missing?
Directly quoting the C11 standard, chapter §6.5.3.3, (emphasis mine)
The result of the logical negation operator
!is0if the value of its operand compares unequal to0,1if the value of its operand compares equal to0. The result has typeint....
So, the result of the logical ! operator is int, so !struct2.s produces int value, and the expression
....(struct.s == !struct2.s)
creates the issue.
NOTE 1:
I guess you use struct as a structure name just for illustration purpose, otherwise, struct being a reserved keyword in C you cannot use that as a variable name.
NOTE 2:
Maybe what you actually meant is (struct.s != struct2.s), but that's also just a (probable)guess.
FOOTNOTE :: Earlier question tagged C++ also, Moving it as footnote but keeping the info just for reference.
Regarding C++, the return type of ! is bool. Ref: C++11, chapter § 5.3.3 (again, emphasis mine)
The operand of the logical negation operator
!is contextually converted to bool(Clause 4); its value istrueif the converted operand isfalseand falseotherwise. The type of the result isbool.
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