ints, floats and chars

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux