In below program how do we make compiler to issue warning/error in case if there is going to be a problem with arithmetic expressions.
If an arithmetic expression is resulting into a value which exceeds the max value of their type i would like the compiler to issue warning/error.
I have compiled below program using gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4)
and the compilation command used is gcc int_promo_flags.c -Wall -Wextra
I was expecting a warning/error from line long long int y = x + INT_MAX;
, but there was no error/warning reported.
By casting x
as (long long) x
we can make the the expression to yeild correct value.
But are there any compiler flags to issue warning if the arithmetic expression is going to overflow its argument type.
#include <stdio.h>
#include <limits.h>
int main()
{
int x = 1;
long long int y = (long long) x + INT_MAX;
printf("%lld\n", y);
return 0;
}