100DaysOfGameDev: Day 8

Today's topic covered logical operators, bitwise logical operators, condition expressions, increment decrement, free store and memory management, lists, and a bit of lambda expressions. The book once again went over the idea of logical operators such as && or ||, emphasizing that they are evaluated from left to right so you can use the idea of shorcircuting the expressions and execute second condtion, because first one holds. Not much interesing stuff for bitwase logical operators, although the comparision between !(not) and ~(complement) was a good reminder that they are not the same. !0(not zero) would mean true, however ~0(complement of zero) will flip the bit pattern, which in two's complement is the value -1. Nothing new for conditional expressions ?:, although should remember that they are a big deal in constant expressions. For increment and decrement, I found this program to copy c-style strings, quite amusing

void cpy(char* p, const char* q)
{
    while (*p++ = *q++);
}

For the free store, a.k.a. heap, a.k.a. dynamic memory, it was good to remember that you wouldn't want to call delete on user defined types twice since it may call their destructors twice and result in some crazy stuff. Also, the syntax for void* operator new (size_t sz, void* p) noexcept; was quite interesting. It basically allows you to supply the pointer, where you want to place the new object, which I never though about. Finally, initializer_list seems intricate topic, or I am just sleepy. Important thing to remember that members in initializer_list are imutable, so you cannot move operation and instead have to use copy operation. An example is:

void f()
{
    initializer_list<int> lst {1,2,3};
    cout << *lst.begin() << '\n';
    *lst.begin() = 2;   // error: lst is immutable
    cout << *lst.begin() << '\n';
}

That's it folks for today. Since I wasn't able to cover lamba expressions fully, I will include it as a part of next post. See you and have a great day/night/sleep!