Grumpy Gamer

Ye Olde Grumpy Gamer Blog. Est. 2004

Unit testing ternary operators...

Oct 29, 2018

…in my compiler makes my head hurt.

i = 1 ? 2 : 3
Assert(i == 2)
i = !1 ? 2 : 3
Assert(i == 3)
i = !1 ? 2 : 3 ? 4 : 5
Assert(i == 4)
i = !1 ? 2 ? 3 : 4 : 5 ? 6 : 7
Assert(i == 6)
i = 1 ? 2 ? 3 : 4 : 5 ? 6 : 7
Assert(i == 3)
i = 1 ? !2 ? 3 : 4 : 5 ? 6 : 7
Assert(i == 4)
i = 1 ? 0 ? 3 : 4 : 5 ? 6 : 7
Assert(i == 4)
i = 1 ? !2 ? 3 ? 4 : 5 : 6 : 7 ? 8 : 9
Assert(i == 6)

Any others I should test?

Casting Values

Oct 25, 2018

I have a scary Halloween story to tell you…

I was running into a bug in my new compiler where large ints where loosing precision. After tracing through my compiler’s C++ code for about an hour trying to catch the spot, I came to this function:

int intConstValue() { return _type == kFloat ? _float : _int; }

It took me a bit of starring and then it hit. Something from the deep recesses of C-lore came jumping up.