Re: regarding type promotion

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Sivaprasad.pv wrote:

> If we consider following sample C language code :
> 
> long long int k=0x123;
> int p=1;
> k = k + p << 33;
> 
> Here the value in variable 'p' is shifted by 33 and then the result
> (only 32 bit result)was promoted to 64 bit.
> Is it an expected behavior?

Yes.

> Is there any way to specify in gcc to perform implicit type promotion
> first and then perform operation on it (without explicit type casting).

I'm not sure exactly what you mean by "without explicit type casting",
but the correct way to write this is

   k = k + (long long)p << 33;

The promotion rules are part of the language standard.

Andrew.

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux