This is the mail archive of the
mailing list for the GCC project.
Re: Is it a bug when use â<<âif the operator is out of the size "0~63"
- From: Miles Bader <miles at gnu dot org>
- To: Yang Yueming <yueming dot yang at huawei dot com>
- Cc: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Fri, 24 Feb 2012 18:04:07 +0900
- Subject: Re: Is it a bug when use â<<âif the operator is out of the size "0~63"
- References: <2ACD72112798CE4AAB7C779F44B073880775F155@szxeml536-mbx.china.huawei.com>
Yang Yueming <firstname.lastname@example.org> writes:
> long long abc = 0x01234567891abcde;
> long long xyz;
> xyz = abc << 65;
> The result of xyz should be "0"ïbut it is "2468acf123579bc" ,same as
> xyz = abc << 1,Why?
Because the shift operators in C have an undefined result when the
shift-count is larger than the size of the type.
As the compiler generally just generates the underlying CPU's shift
instruction, then what happens in practice depends on the CPU.
Different CPUs do different things in such a case, and one popular
alternative is to simply interpret the shift-count modulo the word-size.
> So as for "int a<<35"and etc..
Electricity, n. The cause of all natural phenomena not known to be caused by