| Subject: | Strange bit shifting result with gcc - am I missing something obvious? |
|---|---|
| From: | Boltar |
| Date: | Sun, 30 Mar 2008 12:48:32 -0700 PDT |
| Newsgroups: | comp.lang.c |
On 32 bit linux with gcc 4.2 I get unexpected results with this code:
main()
{
int bits = 32;
printf("%d\n",(int)1 << (int)32);
printf("%d\n",(int)1 << bits);
}
The first printf gives a result of 0, the second gives 1. I checked
with sizeof() and ints are definately 32 bits in size.
I'm sure I'm missing something obvious but can someone tell me what?
Thanks
B2003
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | Re: Reentrant functions and memory allocation, fmassei |
|---|---|
| Next by Date: | sizeof(x), Ioannis Vranos |
| Previous by Thread: | stockings, izurewakaru |
| Next by Thread: | Re: Strange bit shifting result with gcc - am I missing something obvious?, jacob navia |
| Indexes: | [Date] [Thread] [Top] [All Lists] |