This is a function I (want to) use to decode numbers out of unsigned char buffers for networking.
inline unsigned long long getULongLongLongInt(const unsigned char* buffer)
unsigned long long number= (buffer << 56);
number|= (buffer << 48);
number|= (buffer << 40);
number|= (buffer << 32);
number|= (buffer << 24);
number|= (buffer << 16);
number|= (buffer << 8);
No, you can't ignore it. The operand
buffer[i] is of type
unsigned char, which is probably promoted to
int (and if not
unsigned int). If 56 is greater than or equal to the bit width of
int, then the shift is UB.
You need to write
static_cast<unsigned long long>(buffer) << 56 and so on, so the operand will be at least 64 bits long before the shift.