Mantorok Redgormor wrote:
If I have an array of char and there is an integer located in
that char that was assigned by:
int foo=10;
*(int *)&array[position] = foo;
Bad. Casts are evil. Very likely to cause UB due to alignment
restrictions. Assuming array is an array of char, all you need
is:
array[position] = foo;
It's up to you to ensure that foo is in the range a char can
hold. You find out by testing against the values in limits.h.
How can I extract that integer? Any portable way?
I can assign using the above method but can't retrieve it with
the above method.
by:
foo = array[position];
Also, what is a portable method of sending and receiving a
struct that contains bitfields across a network to two different
machines? one is linux on x86 the other is solaris-sparc.. any
idea? Very frustrating problem.
Extract each field, convert it to a text representation, and send
that. The binary image on one machine need not have any
particular relationship to the binary image on another machine.
The recommended method even allows you to follow the process
during operation :-)
--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!