The program below involves a function parameter that is implicitly narrowed. Information is potentially lost.
void func(short) {}
int main()
{
int i = 0x7fffffff;
func(i);
}
If I compile this program (either as C or C++) with gcc using -Wall -Wextra
I receive no warnings!
Surely, this behavior would often be considered undesirable.
Is there some gcc command-line parameter that would trigger a diagnostic message when these narrowing conversions occur?
Use -Wconversion
for gcc/clang. /W4
can be used for VC++.
online compiler
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