Yang Yueming <yueming.y...@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.

Reply via email to