Skip to end of metadata
Go to start of metadata

Available since firmware version 7.6

Table of Contents

 


 

Conditional Compilation allows boolean constants to determine whether a section of code should be compiled. Conditional compilation values are defined by the #const identifier and has the form:

#const <constant-name> = <expression> 

Examples of valid expressions

Criteria:

  • This initial release only supports boolean constant values.

  • Constant names must be composed of alphanumeric characters, and optionally, the underscore _ character. There is no limit to the length of a constant name.

  • Constant names are case-insensitive.

  • A constant name should not be redefined if it has already been defined prior. 

Defining a Constant

A constant can be defined in 2 ways:

  • A manifest attribute in the channel package
  • A constant locally scoped to individual BrightScript files

Manifest Constant

Conditional compilation values can be specified in the manifest via the bs_const attribute:

More than one conditional compilation value can be specified via semi-colon separated key-value pairs:

Uses

 There are a variety of ways Conditional Compilation can be used:

Example demonstrating use of manifest constants
Example demonstrating locally scoped constants

An #error constant can also be used to force a compilation error with an error message:

Example demonstrating usage of #error constant

Block Comments

Conditional Compilation can also be used to form block comments. Previously, each line of code needed to be commented out. 

Example of code block comments
Example of commenting out code

Calling this function would result in a compile time error. To re-enable this function, change #if false to #if true


  • No labels