123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|373|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Off Topic -> C# Bool vs Int

Mon, 16 Jan 2012, 13:57
Afr0
The C# compiler is whinging because it cannot convert a boolean expression to an integral value :|

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Mon, 16 Jan 2012, 13:57
HoboBen
In C#, Convert.ToInt32 compiles down to a ternary expression that treats 1 == true (although this is an abstraction that you would ignore normally). You could also try

int a = (expression) ? 1 : 0;

but ternary expressions are ugly (although so is Convert.ToInt32).

source

I don't know why you're storing a boolean in an integer value. Even in C where you can do this without a problem, it's probably a logical error to give a value two meanings in that way.

Less ambiguous is explicitly saying what value a would have given the condition, e.g.

if (expression) { a = 1; } else { a = -1; }
if (expression) { a = 1; } else { a = 0; }

Or similar.

Slightly more typing, but it's more explicit than guessing how booleans are represented internally (e.g. sometimes they're just anything that is non-zero, so a C function that returns true could return -99 and be completely correct).

Or, if a is really a boolean, make it a boolean.

-=-=-
blog | work | code | more code
Mon, 16 Jan 2012, 15:29
Afr0
I don't know why you're storing a boolean in an integer value. Even in C where you can do this without a problem, it's probably a logical error to give a value two meanings in that way.


Because the original source does it! I still haven't been able to generate anything but squeaking, but I just made the decompressed files increase in size, so I'm getting there.
The thing is that the original source was directly ported from raw ASM, so porting it is a pain in the ass.

The source does this:



Linky (Fuck you EA, I didn't reverse engineer this!)

I'll try using ToInt32.

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Mon, 16 Jan 2012, 16:08
JL235
Ah, I see why it's not a bool. a is set to 1 or 0, and then it's used to set an upper bit on the next loop. You get similar stuff with maths, such as rounding without any branches (which is often efficient on the more exotic CPUs with very long pipelines).

Rather then toInt32, just use the ternary operator, like Ben suggested.


Mon, 16 Jan 2012, 23:43
Afr0
Ah, right.
Thanks!