0

How many instructions are there in following function according to HIS code metrics?

  static uint16 CalcSignalBjbCurrents()
{
   uint16 u16Current;
   if(TRUE == bCurrValid)
   {
      if()
      {
         u16Current = 2;
      }
      else if()
      {
         u16Current = 1;
      }
      else
      {
         u16Current = 123;
      }
   }
   else
   {
      u16Current = 22;
   }

   return u16Current;
}

Details:

I can't find any difference between "Statement" and "Instruction" in C. I'll really appreciate if someone can answer it with valid reference.

I'm getting different values for number of instructions/statements when checking code metrics of this function using our internal SCA analyzer than when checking with SourceMonitor. My analysis of problem is that SourceMonitor is counting compound statements (like conditional tree) as multiple statements where our internal script is counting whole conditional tree as one instruction.

Our Script: Number of Instructions->8;

Source Monitor: Number of Stetments->11;

HIS code metrics: http://docplayer.net/6136232-His-source-code-metrics.html

Has9
  • 41
  • 1
  • 7
  • 1
    "Instruction" is not a concept that is part of the C programming language. – EOF Mar 14 '17 at 16:13
  • I know that but please refer to HIS Source Code Metrics "QA-C: STST3" before down voting or commenting – Has9 Mar 14 '17 at 16:16
  • 2
    Trick question, the code fragment is not valid C – JeremyP Mar 14 '17 at 16:17
  • 1
    omg, why this community is so toxic lol, I can't send you my actual production code mate, it's not a trick question, PS: the variable types are defined types a common practice used in embedded software development – Has9 Mar 14 '17 at 16:25
  • @Has9: It would help if you provided a direct link to such metrics. – John Bode Mar 14 '17 at 16:48

1 Answers1

0

Well, the linked document refers back to the C standard, which defines a statement as "an action to be performed", which frankly is open to interpretation when it comes to these types of analyses.

If I break it down by syntax, I count 15 distinct statement productions, but those don't necessarily translate into distinct actions.

I count 4 assignment statements, distributed among 3 if statements, plus a return statement - that adds up to 8. Syntactically speaking, declarations are not statements, and I don't count the declaration towards that total.

John Bode
  • 119,563
  • 19
  • 122
  • 198