This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
std min error during optimization
- From: TRaj <tryitn1 at gmail dot com>
- To: libstdc++ at gcc dot gnu dot org, gcc-help at gcc dot gnu dot org
- Date: Fri, 24 Jul 2009 09:09:20 +0530
- Subject: std min error during optimization
- References: <b74b36da0907232036x6282340bh4c31e34915a7aa80@mail.gmail.com>
hi,
??I'm not subscribed to this list. Please add me to your replies.
??i've this code at?http://codepad.org/L1Ko85ff?or below which gives
different answers 8 and 9 (last line) ?based on optimization (-O2) and
-O0 on my g++ cygwin (3.4).
When i redefine the min by mymin
#define mymin(a,b) ((a<b)?(a):(b)) it gives me 8 but when i replace it
with std:min it gives me 9 ?at -O0 on gcc 4.3.
Am i doing something wrong in the below code ?
#include<cstdio>
#include<iostream>
#include<sstream>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<iterator>
#include<iostream>
#include<cctype>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<list>
using namespace std;
const int N=7;
int done[1<<12],gdo2[1<<12];
const int INF=1000000;
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;
}
int main(){
done[0]=done[1]=done[3]=done[2]=done[6]=done[4]=done[5]=done[7]=done[15]=1;
cout <<g(15,0)<<endl;
return 0;
}