This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Is it a bug when use â<<âif the operator is out of the size "0~63"


Yang Yueming <yueming.yang@huawei.com> 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..

Same thing.

-miles

-- 
Electricity, n. The cause of all natural phenomena not known to be caused by
something else.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]