Advertisement

integer constants in the switch-clause

Started by August 22, 2005 08:21 PM
5 comments, last by WitchLord 19 years, 3 months ago
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
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

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement
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.



AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This also happens in C on linux compiling with gcc.

ace
"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
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
Advertisement
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.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement