Automatic integer - bool convertion

Recommended Posts

Hello! One of the things I find utterly strange in AngelScript is the inability to simply write:
int a;
...
if (a)
{


Why am I always forced to write:
int a;
...
if (a != 0)
{


or
...
if ((a & 1) != 0)
{


instead? This is very unfriendly to end-programer and counter-intuitive. Is there any possibility this feature will be implemented in the near future?

Share on other sites
You're thinking like a C++ programmer. It's not so counter intuitive for non-C++ programmers, and actually quite common cause for bugs with inexperienced programmers.

However, I can add a engine property to allow the application developer to choose if these conversions should be allowed or not.

Share on other sites
Like Andreas said, it is a cplusplusy thing. As soon as you try out C# you'd find the same thing as AngelScript.
ints are not bools and you are making a technical assumption that the value of False is the same as integer zero and True is any other value. (which, for the most part is always right)

Share on other sites
it's not only it's a C++ thing, it's also a C thing, a PHP thing, a javascript thing, insert_language_of_your_preference thing.

Quote:
 Original post by midniteAs soon as you try out C#
I have and I don't think I'll ever come back to it :)

Share on other sites
On this subject, one thing that always bugs me off is that some operations with enum defined values generate errors at compile time. We use enums to "feed" the script with all kind of predefined values, many being bitflags, and operating with these bitflags can be pretty ugly at times. Example of compiling:

The negation is a illegal operation. I asume this is cause it tries to negate the enum value itself, so it fails. I use this trick to force it to generate a copy of itself to operate (well, that's my guess):

Then it works. But it's pretty ugly to have to add the cast every time we want to use some of the predefined bitflag constants. Do you think it would be possible/convenient to force it to generate the copy on that kind of operations?

[Edited by - jal_ on March 16, 2009 6:08:27 AM]

Share on other sites
Yes, I'll add this. bitwise complement should work for enum values as well.

Share on other sites
I've checked in the fix for bitwise complement and also unary negate for enum values.

Create an account

Register a new account

• Forum Statistics

• Total Topics
627694
• Total Posts
2978671

• 19
• 14
• 12
• 10
• 12