Jump to content

GSourceHandle ???


AlexK17

Recommended Posts

Hi.

GSourceHandle enterHandle = ginputGetToggle(GINPUT_TOGGLE_ENTER);

Why can this string cause a compiler error? 

Error[Pe059]: function call is not allowed in a constant expression

but if use

#define enterHandle   ginputGetToggle(GINPUT_TOGGLE_ENTER)

It does not cause an error and works fine.

Compiler IAR 7.5

Best regards, Alexandr.

 

 

Link to comment
Share on other sites

If the line specified is right at the top of the function my guess is that it will work. If it is not at the top then you are running into a common C, C++ language misconception.

C does not allow variable definitions except at the top of a block. Once a non-variable definition statement has occurred variable definitions are not allowed in the block.

Whilst the C language does not allow this, C++ does. As many C compilers have associated C++ compilers many C compilers relax the rules and allow such definitions eg gcc.

My guess is that the IAR C compiler follows the language standard and doesn't allow this.

In general in C it is a good idea to seperate variable definitions from code to set the variables.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...