Re: New filesystem for Linux



On Fri, Nov 03, 2006 at 06:36:09PM +0100, Oleg Verych wrote:
On Fri, Nov 03, 2006 at 06:09:39PM +0100, Mikulas Patocka wrote:
In gmane.linux.kernel, you wrote:
[]
From: Andrew Morton <akpm@xxxxxxxx>

As Mikulas points out, (1 << anything) won't be evaluating to zero.

How about integer overflow ?

C standard defines that shifts by more bits than size of a type are
undefined (in fact 1<<32 produces 1 on i386, because processor uses only 5
bits of a count).
,--
|#include <stdio.h>
|int main(void) {
| unsigned int b = 1;
|
| printf("%u\n", (1 << 33));
| printf("%u\n", (b << 33));
| return 0;
|}
|$ gcc bit.c && ./a.out
`--

There *is* difference, isn't it?

It's undefined, and the results with your example depend on the gcc
version and optimization level.

E.g. with gcc 4.1, there is *no* difference any more if you turn on
optimization.

cu
Adrian

--

"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon Seed

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



Relevant Pages

  • Re: New filesystem for Linux
    ... C standard defines that shifts by more bits than size of a type are ... |int main{ ... and the results with your example depend on the gcc ... version and optimization level. ...
    (Linux-Kernel)
  • Re: Properly controlling CFLAGS/CXXFLAGS
    ... apparently breaks too many software packages. ... As GCC says, the results are undefined when the flag is not passed. ... but works fine with any other optimization level. ... Yes, -fno-strict-aliasing is indeed useful to get some old, buggy code (as ...
    (freebsd-hackers)
  • Re: [PATCH] likely cleanup: remove unlikely for kfree(NULL)
    ... On Wed, 26 Apr 2006, Arjan van de Ven wrote: ... what I would like is kfree to become an inline wrapper that does the ... with the VRP pass) if gcc can prove it's not NULL. ... There had been need of rain for many days. ...
    (Linux-Kernel)
  • Re: "kernel + gcc 4.1 = several problems" / "Oops in 2.6.19.1"
    ... If the same kernel compiled with gcc 3.4.6 works fine, ... into one of the mysterious problems with gcc 4.1. ... Does the machine hang completely, or is any useful information like e.g. ... There had been need of rain for many days. ...
    (Linux-Kernel)
  • 2.6.12-rc5-mm1: fork connector doesnt compile with gcc 2.95
    ... The following compile breakage with gcc 2.95 is caused by ... There had been need of rain for many days. ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)