This is the mail archive of the gcc-help@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: std min error during optimization


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


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