309 views
in Embedded Wizard Studio by
Der all,

How to enclose a local variable in a C preprocessor block?

For example in a slot I define a variable like this:

$if !$prototyper
var bool loadScreenSaver = false;
$endif

then since that variable is used in native block and is enclosed in a C Preprocessor block, the C compiler give me a unused variable warning, when the flag is false.

I tried to make somenthing like this:

$if !$prototyper
native
{
#if (EnableScreenSaver)
}
var bool loadScreenSaver = false;
native
{
#endif
}
$endif

but the generator create the variable anyway and the C code is:

XBool loadScreenSaver;

#if (EnableScreenSaver)
loadScreenSaver = 0;
#endif

Is there a way to avoid this?

We are using EWS8.20.

Looking forward your kind reply

Thanks in advance.

Best regards

Gianni Perugini

1 Answer

0 votes
by

Hello Gianni,

if the local variable is declared but not used, no Chora code is generated and Embedded Wizard reports a warning. If the local variable is involved in a Chora expression (even just an initialization expression), Chora compiler will generate the variable. This unused local variable elimination is in Chora compiler rudimentary. The 'C' compiler is more precise. It reports the warning, when the local variable really doesn't make sense.

The problem, you have here, is the approach to use conditional compilation of Chora code depending on a 'C' define. The Embedded Wizard, however, has no idea about the eventually existing 'C' defines. Since the variable is used in 'C' code only, one possible workaround would be, to declare the variable within a native block as 'real' 'C' variable. For example:

// declare 'C' local variable
$if !$prototyper
  native
  {
    #if (EnableScreenSaver)
      XBool loadScreenSaver;
    #endif
  }
$endif

// use the 'C' local variable
$if !$prototyper
  native
  {
    #if (EnableScreenSaver)
      loadScreenSaver = 0;
    #endif
  }
$endif

Hope it helps you further!

Best regards

Paul banach

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...