This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: std min error during optimization
- From: Ian Lance Taylor <iant at google dot com>
- To: TRaj <tryitn1 at gmail dot com>
- Cc: libstdc++ at gcc dot gnu dot org, gcc-help at gcc dot gnu dot org
- Date: Fri, 24 Jul 2009 18:13:03 -0700
- Subject: Re: std min error during optimization
- References: <b74b36da0907232036x6282340bh4c31e34915a7aa80@mail.gmail.com> <b74b36da0907232039me8530e6y75c7ae3f87b02ef9@mail.gmail.com>
TRaj <tryitn1@gmail.com> writes:
> int g(int mask,int lvl){
> assert(mask<(1<<N));
>
> printf("MASK=%d\n",mask);
>
> if(gdo2[mask]) return gdo2[mask];
>
> if(lvl==N){
> if(done[mask]) return INF;
> return mask;
> }
> int ans=INF,i;
> if(done[mask]==0) ans=mask;
> for(i=0;i<N;i++)
> if((mask&(1<<i))){
> ans=min(ans,min(g(mask^(1<<i) ,lvl+1),g(mask,lvl+1)));
> }
>
> return gdo2[mask]=ans;
>
> }
In this line:
> ans=min(ans,min(g(mask^(1<<i) ,lvl+1),g(mask,lvl+1)));
the function g calls itself twice. The order of those function calls is
undetermined and will be different depending upon the function is
compiled. This is a problem since g acts differently based on global
variable state.
Ian