Why do these two functions different results?

 

Why do these two functions different results? I've always used method 1, but I found the results unsatisfactory, so I tried method 2 and it gave me the desired results.

Method 1:

bool Save_History_StrongConsensus(const char s)
{
   bool Ret = false;
   Ret = Ret || Save_History_StrongConsensus(s, Data[s].AA_Sonen,  0);
   Ret = Ret || Save_History_StrongConsensus(s, Data[s].AA_SPoT,   1);
   Ret = Ret || Save_History_StrongConsensus(s, Data[s].AA_DTC,    2);
   Ret = Ret || Save_History_StrongConsensus(s, Data[s].AA_Strong, 3);
   Ret = Ret || Save_History_StrongConsensus(s, Data[s].AA_XHRM,   4);
   Ret = Ret || Save_History_StrongConsensus(s, Data[s].AA_FSM,    5);
   Ret = Ret || Save_History_StrongConsensus(s, Data[s].AA_ADX,    6);
   Ret = Ret || Save_History_StrongConsensus(s, Data[s].AA_HSMR,   7);
   Ret = Ret || Save_History_StrongConsensus(s, Data[s].AA_STFM,   8);
   Ret = Ret || Save_History_StrongConsensus(s, Data[s].AA_RSI,    9);
   return Ret;
}

Method 2:

bool Save_History_StrongConsensus(const char s)
{
   bool Ret = false;
   if (Save_History_StrongConsensus(s, Data[s].AA_Sonen,  0)) Ret = true;
   if (Save_History_StrongConsensus(s, Data[s].AA_SPoT,   1)) Ret = true;
   if (Save_History_StrongConsensus(s, Data[s].AA_DTC,    2)) Ret = true;
   if (Save_History_StrongConsensus(s, Data[s].AA_Strong, 3)) Ret = true;
   if (Save_History_StrongConsensus(s, Data[s].AA_XHRM,   4)) Ret = true;
   if (Save_History_StrongConsensus(s, Data[s].AA_FSM,    5)) Ret = true;
   if (Save_History_StrongConsensus(s, Data[s].AA_ADX,    6)) Ret = true;
   if (Save_History_StrongConsensus(s, Data[s].AA_HSMR,   7)) Ret = true;
   if (Save_History_StrongConsensus(s, Data[s].AA_STFM,   8)) Ret = true;
   if (Save_History_StrongConsensus(s, Data[s].AA_RSI,    9)) Ret = true;
   return Ret;
}
 
Nguyen Van LuongWhy do these two functions different results? I've always used method 1, but I found the results unsatisfactory, so I tried method 2 and it gave me the desired results.
  1. Does Save_History_StrongConsensus(A,B,C) return a bool? If yes the results are the same.
  2. Method 1, just or's the values. Invalid with integers greater than 1.
  3. Method 2, check for zero or non-zero, works with integers.
 
William Roeder #:
  • Does Save_History_StrongConsensus(A,B,C) return a bool? If yes the results are the same.
  • Method 1, just or's the values. Invalid with integers greater than 1.
  • Method 2, check for zero or non-zero, works with integers.
  • Of course, the Save_History_StrongConsensus(A,B,C) function returns a bool. It's the function below:

    bool Save_History_StrongConsensus(const char s, const char AA, const char idx)
    {
       bool Ret = false;
       if      (AA != 0 && Data[s].StrongConsensus_Begin[idx] == T1970) Ret = Update_History_StrongConsensus(s, idx, true);
       else if (AA == 0 && Data[s].StrongConsensus_Begin[idx] != T1970) Ret = Update_History_StrongConsensus(s, idx, false);
       return Ret;
    }


    bool Update_History_StrongConsensus(const char s, const char idx, const bool bAddNew)
    {
       //Create or open the database in the common terminal folder
       string filename = Filename(EXPERT_NAME);
       int db = DbOpen(filename, __FUNCTION__);
       if (db == INVALID_HANDLE)
       {
          Print("DB: ", filename, " open failed with code ", GetLastError());
          return false;
       }
       else
       {
          //TODO...
       }
       
       //Close the database
       DatabaseClose(db);
       
       return bAddNew;
    }
     
    Your method 1 has "shortcut effect" (brief:estimate) of logical expression.