Option Checking in C Code

You can also check the source to determine if an option is active. The EBNF syntax is:

  OptionActive = "
  __OPTION_ACTIVE__" "(" string ")".
  
  

The above is used in the preprocessor and in C code, as shown:

Listing: Using __OPTION__ to check for active options.


#if __OPTION_ACTIVE__("-W2")

  // option -W2 is set

#endif

void main(void) {

  int i;

  if (__OPTION_ACTIVE__("-or")) {

    i=2;

  }

}

You can check all preprocessor-valid options (e.g., options given at the command line, via the default.env or project.ini files, but not options added with the #pragma OPTION: Additional Options). You perform the same check in C code using -Odocf and #pragma OPTIONs.

As a parameter, only the option itself is tested and not a specific argument of an option.

For example:

  #if __OPTION_ACTIVE__("-D") /* true if any -d option given 
  */
  
  
  #if __OPTION_ACTIVE__("-DABS") /* not allowed */
  
  

To check for a specific define use:

  #if defined(ABS)
  
  

If the specified option cannot be checked to determine if it is active (i.e., options that no longer exist), the message "C1439: illegal pragma __OPTION_ACTIVE__" is issued.