Jump to content
  • Advertisement
Sign in to follow this  
juhnu

integer constants in the switch-clause

This topic is 4834 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, We are trying to use a constant integer defined inside AngelScript as for the case label in a switch clause. Something like: const int Foo=1; ... switch (bla) { case Foo: } The compiler complains that the Foo should be a constant integer expression. However the script's documentation says case-label takes an INT_CONST expression. switch( INT_EXP ) { case INT_CONST: STATEMENT default: STATEMENT } Now. How could I define an integer constant within the AngelScript and use that with the switch-clause. I wouldn't like to use some third-party preprocessor to do this. Thanks for the help, Juhani

Share this post


Link to post
Share on other sites
Advertisement
This looks like a bug in AngelScript. I'll investigate it and have it fixed as soon as possible.

Thanks for notifying me.

Regards,
Andreas

Share this post


Link to post
Share on other sites
I looked into this, and it seems the compiler doesn't treat the declared const int as a literal constant value that the switch case expects. This isn't a bug, just a feature that haven't been implemented yet.

I'll see if I can implement this for the next WIP release, but I cannot promise anything.



Share this post


Link to post
Share on other sites
"looked into this, and it seems the compiler doesn't treat the declared const int as a literal constant value that the switch case expects. This isn't a bug, just a feature that haven't been implemented yet.

I'll see if I can implement this for the next WIP release, but I cannot promise anything."


I see, for the time being before this feature is implemented, could you recommend some work around for the problem? is a preprocessor the only way to go?


Thanks a lot for your reply.



Juhani

Share this post


Link to post
Share on other sites
You could do something like this?

switch(obj)
{
case 1/*MYCASE*/:
break;
}

Later you could use regular expressions to fix easily erase the 1 and the comments around MYCASE

Share this post


Link to post
Share on other sites
At the moment my suggestion would be to go with numeric constants, like Rain Dog suggested.

I'm sure it won't be long before I have the const int variables working with switch cases as well. I've already got the solution, I just need some time to implement and test it. I may not have it ready for the next WIP, but I promise that I will implement it for the final 2.4.0 version.

If you really must use named constants already, then a preprocessor is currently the only way it could be done. If decide to go with this, then may I suggest Deyja's preprocessor. It is already being successfully used with other AngelScript projects.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!