Booleans in Symbian

This error wasted 30 minutes of my time yesterday:

unresolved external symbol "int __cdecl operator==(int,enum TTrue)"

I understood that it was something wrong with one of my == statements but I couldn’t for the life of me figure out what. So after a while I turned to the old trusted friend google for help and I found this Symbian Knowledge Base Entry, basically that error message is given on purpose to catch coding mistakes.

Doing the below with Symbian’s TBool class is not allowed.

    TBool loop = ETrue;
    do
        {
        // ...
        }
    while (loop == ETrue);

This is how it should be written:

    TBool loop = ETrue;
    do
        {
        // ...
        }
    while (loop);

A more complicated example from the above linked knowledge base article:

     if (myTBool != theirTBool)
        {
        doSomething();
        }

should be written as:

    if ((myTBool && !theirTBool) || (theirTBool && !myTBool))
        {
        doSomething();
        }

So now you know to be careful when using booleans in your Symbian code.