This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: -funswitch-loops not effective?


On Mon, 17 Jan 2005, Andrew Pinski wrote:

> > void foo(int);
> > void bar(int);
> > 
> > extern const _Bool flag;
> > 
> > void foobar(int n)
> > {
> >         int i;
> >         for (i=0; i<n; ++i)
> >                 if (flag)
> >                         foo(i);
> >                 else
> >                         bar(i);
> > }
> 
> 
> Because even though flag is const in this TU, but does
> not have to be in a different TU, which case foo and bar
> can modify flag.  If you look at the tree dumps with
> the vops turned on, you will see this.

This sort of type incompatibility is not valid C: flag must have 
compatible types in all translation units, and "_Bool" and "const _Bool" 
are not compatible.

However, if you have "const _Bool *p" and used *p instead of flag, then *p 
could indeed be modified through other pointers.

-- 
Joseph S. Myers               http://www.srcf.ucam.org/~jsm28/gcc/
    jsm@polyomino.org.uk (personal mail)
    joseph@codesourcery.com (CodeSourcery mail)
    jsm28@gcc.gnu.org (Bugzilla assignments and CCs)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]