Jump to content
Sign in to follow this  

GSourceHandle ???

Recommended Posts


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.



Share this post

Link to post
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.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...