Well, to begin with let's assume i am writing a 32-bit program and that:
character (char) = 1 byte
integer (int) = 4 byte
And i have a an array of 4 characters. In assembly i could move all four bytes into a 32-bit register and do arithmetic operations on it.

In C/C++ would be moving an array of 4 characters into 1 integer variable (except it will be in ram instead of a register).

The idea is to do SIMD like operations without the compiler optimization nor the asm block.
Posted on 2011-10-22 08:53:40 by banzemanga
Type-casting, what else.
char buff[16];
#if 1
int i = *((int *)buff); // c-like cast
#else
int i = *reinterpret_cast<int *>(buff);
#endif
Posted on 2011-10-22 09:15:22 by drizz
Thank you @drizz. It worked. My problem was that i was putting the asterisk outside the integer casting like this:
int *temp = (int) *buff; //or
int *temp = *(int) buff;

What if i want to do the backwards? Move the integer value onto the character array without resorting pointers like i am doing?
Posted on 2011-10-22 14:45:20 by banzemanga