Login Page - Create Account

Support Board


Date/Time: Sun, 05 May 2024 07:33:27 +0000



Post From: Question about initialization of variables

[2019-03-13 15:57:05]
User257019 - Posts: 25
Hello team,

I´m learning ACSIL and doing a simple study that will draw an horizontal line in the maximum and minimums. Something like the code below.

Is it correct to initialize maximum and minimum with the "if (!maximum)"? meaning, if it´s NULL, then assign the value of currentHigh.

I am sure there is a more elegant way regarding your best practices I could use? THANKS!


SCSFExport scsf_DrawMaxAndMin(SCStudyInterfaceRef sc)
{

  if (sc.SetDefaults)
  {
    ...
  }

  int& maximum = sc.GetPersistentInt(1);
  int& minimum = sc.GetPersistentInt(2);
  
  int currentHigh = sc.BaseDataIn[SC_HIGH][sc.Index];
  int currentLow = sc.BaseDataIn[SC_LOW][sc.Index];

  if (!maximum) // Meaning... is it NULL?
    maximum = currentHigh;
  
  if (!minimum) // Meaning... is it NULL?
    minimum = currentLow;

  if (maximum < currentHigh)
    maximum = currentHigh;
  
  if (minimum > currentLow)
    minimum = currentLow;

// Drawings

}