Overview

Structure definitions support two forms of conditions: switch and if statements.  

NOTE: The support for conditionals in Structure definitions differ from Structure Functions.

switch statement

The switch statement allow users to define conditional structure elements based on another structure variable or expression.  The general form is:

switch (<expression>)

{

case <expression>:

  <<DATA TYPES>>

  break;

case <expression>:

  <<DATA TYPES>>

  break;

default:

  <<DATA TYPES>>

  break;

};     

 

Example:

#include "standard-types.hsl

struct conditionalExample

{

  WORD type ;

  WORD len ;

 

  switch (type)

  {

  case 1:

    WORD value ;
    __verify(len == 2);

    break;

  case 2:

    DWORD value ;
    __verify(len == 4);

    break;

  default:

    blob value[len];

    break;

  };

};

Limitations:

if statement

The statements allows users to define conditional structure elements using if, else if, else statements and resembles the C/C++ language.  Each branch of the if statement must include an open and closing brace and the last branch must included a semicolon.

Form 1:

if (<expression>)

{

 

} ;

 

Form 2:

if (<expression>)

{

 

}

else if (<expression>)

{

 

}

else

{

 

} ;

More Information on Structure Definitions

Definition Overview, Data Types, Enumerated Types, Arrays, Strings, Bitfields, Expressions, Conditionals, Functions, Verification, Library Settings, Structure Settings, and Reserved Words and Symbols.