lkml.org 
[lkml]   [2002]   [Jan]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH] C undefined behavior fix
On 9 Jan 2002, at 19:19, Peter Barada wrote:

>
> >Even
> >
> >int b;
> >volatile const int a = 5;
> >b = a - a;
> >
> >can not be optimized to
> >
> >b = 0;
>
> Until you define the scope of the variables, you can't make that
> assertion. If the code is:
>
> int b;
> volatile const a=5;
> void stuff()
> {
> b = a - a;
> }
>
> I can see how a can change in the midst of the execution since
> some other code has access to a since its global scope.
>
> If the code is:
>
> int b;
> void stuff()
> {
> volatile const a=5;
>
> b = a - a;
> }
>
> Then the code can be optimized to 'b = 0;' since nowhere in the scope
> of 'a' does anyone take its address(which would allow it to be changed).

I could have hardware attached directly to the data bus (a hardware
debugger for instance) that watches for the value 5 to appear. This is
beyond the knowledge of the compiler.

> 2) No one takes the address of b, so there is no way for any external
> hardware/thread to modify b.

see above. You don't need to take the address to catch the variable
access.

MSB

--
Who is this General Failure,
and why is he reading my disk ?

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

\
 
 \ /
  Last update: 2005-03-22 13:15    [W:0.072 / U:0.148 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site