This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
ints, floats and chars
- From: "Evert Lammerts" <lamme202 at tech dot nhl dot nl>
- To: gcc-help at gcc dot gnu dot org
- Date: Mon, 28 Aug 2006 14:29:37 +0200 (CEST)
- Subject: ints, floats and chars
Hi there,
I might very well be at the wrong place to ask such a question - if I am,
does anyone know a good resource where I can post it?
Programming in C, and only C, I have some data stored in several numeric
types. This data needs to be put together in a single package containing
seperators (I'd like a char array). this package will be sent over to an
other computer and then disected again.
Let's say I have an U int and a float. These types are all 4 bytes. Now I
want to copy that data into a char array, including a seperator S, coming
to the following package / memory block:
-------------------------------------
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
-------------------------------------
U int S float
Casting ints and floats to char[] is appearantly not an option (that's
what gcc tells me anyway). I don't really understand why - if a float is 4
bytes, and i make a char[4] to try and store the data in, both types are
the same size. Why am I not allowed to do this? And what would be an
alternative?
Thanks, Evert Lammerts
--
SMTP-server Noordelijke Hogeschool Leeuwarden.
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.