Login Page - Create Account

Support Board


Date/Time: Sun, 09 Mar 2025 13:59:28 +0000



Post From: corruption of variables on simple code using standard arrays

[2022-03-01 09:02:21]
User824913 - Posts: 15
After a day of testing with one of my studies, I isolated a problem that I did not expect. Here I am repeating a simple code that shows the anomaly

// The top of every source code file must include this line
#include "sierrachart.h"
SCDLLName("Provette")

bool flag=false;
int tempi[100];
int timeInMilliseconds;

SCSFExport scsf_Provette(SCStudyInterfaceRef sc)
{
  // Section 1 - Set the configuration variables and defaults
  if (sc.SetDefaults)
  {
    sc.GraphName = "Provette";

    sc.AutoLoop = 1; //Automatic looping is enabled.

    sc.Subgraph[0].Name = "Name";
    sc.Subgraph[0].DrawStyle = DRAWSTYLE_LINE;
    sc.Subgraph[0].PrimaryColor = RGB (0, 255, 0);

    sc.Input[0].Name = "Float Input";
    sc.Input[0].SetFloat(0.0f);

    return;
  }
  SCString sTxt;
sc.AddMessageToLog(sTxt.Format("flag--> %d",flag),0);


  int timeInMillisecondsTmp = sc.CurrentSystemDateTimeMS.GetTimeInMilliseconds();

  int lassoTempo=timeInMillisecondsTmp-timeInMilliseconds;
  timeInMilliseconds=timeInMillisecondsTmp;
  tempi[0]=lassoTempo;
  double tTot=0;
  for (int i=99;i>=0;i--){
    tempi[i+1]=tempi[i];
    tTot=tTot+tempi[i];
  }
  double tempoMedio=tTot/100.0;
  bool test=true;
}
In the first few cycles the flag variable has value 0 as one would expect, but after a few cycles its value becomes random and changes continuously.
Where is the problem?
thks a lot