On Feb 14, 7:48 pm, "Daniel T." <danie...@earthlink.netwrote:
Quote:
On Feb 14, 7:45 am, chuck <noem...@gmail.comwrote:
Quote:
Quote:
I am trying to 'force' a character array to act as an int array. I
want to use 4 chars to store an actual int , in the array, not a number
converted to a string. So every 4 characters of my array is really a
full integer value.
Quote:
Quote:
Can anyone post a simple example on how to do this?
Quote:
Are the ints in your system sizeof( 4 )? Is the memory in the
char array formatted with the same endian as what the system
uses?
Quote:
If so, then simply int* myArr = reinterpret_cast<int*>( myChar );
That's a good recepe for a core dump on a lot of machines.
You're forgetting alignment considerations.
Quote:
Otherwise, you will have to do some real work converting the
raw memory into the format you need.
No real work, just a bit of shifting and masking.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34