Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

doubt regarding operations on "int" flavors

I am having following doubt regarding "int" flavors (unsigned int, long int, long long int).

When we do some operations(* , /, + , -) between int and its flavors (lets say long int) in 32bit system and 64bit system is the implicit typecast happen for "int"

for example :-

int x ; long long int y = 2000;

x = y ; (Higher is assigned to lower one data truncation may happen) I am expecting compiler to give warning for this But I am not getting any such warning. Is this due to implicit typecast happen for "x" here. I am using gcc with -Wall option. Is the behavior will change for 32bit and 64bit.

Thanks Arpit

like image 692
Arpit Avatar asked Dec 07 '22 02:12

Arpit


1 Answers

-Wall does not activate all possible warnings. -Wextra enables other warnings. Anyway, what you do is a perfectly "legal" operation and since the compiler can't always know at compile-time the value of the datum that could be "truncated", it is ok it does not warn: programmer should be already aware of the fact that a "large" integer could not fit into a "small" integer, so it is up to the programmer usually. If you think your program is written in not-awareness of this, add -Wconversion.

like image 60
ShinTakezou Avatar answered Dec 09 '22 15:12

ShinTakezou