jeudi 31 décembre 2015

c++ constexpr pointer casting

The code below explains the problem

    constexpr int x = *(reinterpret_cast<const int*>("abcd")); //wrong
    constexpr int y = ("abcd")[0]*1l + ("abcd")[1]*256l + ("abcd")[2]*256*256l + ("abcd")[3]*256*256*256l; //ok

How can I do such type casting in constexpr expression?

Aucun commentaire:

Enregistrer un commentaire