Alors oui pour un étudiant, il n'y comprendra rien. Mais ce qui me fait vraiment peur sur developpez.com c'est de voir que des gens que l'on pourrais penser expérimenté professionnellement ne savent pas ça, et reste dans leur carcan.
Je suis sur que ce code-ci en fera bouillir plus d'un:
Code:
1 2 3 4 5 6 7 8
|
PtrType* IfAThenAElseB(PtrType* A, PtrType* B)
{
const intptr intptrA = reinterpret_cast<intptr>(A);
const intptr intptrB = reinterpret_cast<intptr>(B);
const intptr Mask = -(!intptrA); // Mask which all bit is set if intptrA is zero or all bit unset if intptrA is not zero
return reinterpret_cast<PtrType*>(intptrA | (Mask & intptrB));
} |
ou ça:
Code:
1 2 3 4 5 6 7 8
|
PtrType* IfAThenBElseC(PtrTypeTest A, PtrType* B, PtrType* C)
{
const intptr intptrB = reinterpret_cast<intptr>(B);
const intptr intptrC = reinterpret_cast<intptr>(C);
const intptr Mask = -(!intptr(A));// Mask which all bit is set if A is zero or all bit unset if A is not zero
return reinterpret_cast<PtrType*>((intptrB & ~Mask) | (intptrC & Mask));
} |
Et pourtant ce sont toutes ces petites choses qui font que vous pouvez avoir du temps réel réaliste.
Oh et ça passe sur tout les X86 et autres... :)