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

Re: Bag o' Questions



Wrap your paragraphs at 72 characters?

On Sat, May 06, 2000 at 12:19:25AM -0400, Patrick Dahiroc wrote:
> 
> 2) (C/C++) I need to put ints, floats, and doubles in to char* arrays
> (weird huh).  Essentially what I would like the is to have the byte
> information stored in a float (4bytes) and a char[4] (total 4bytes) to
> be identical.  What's the proper way to do this?

Something like this should work:
  char *arr[4];
  float fl=4.2;
  *(float *)arr=fl;

i wouldn't count on a float being 4 bytes though, it probably depends on
the implimentation. Also, if you're thinking of using this as a way to
have data portable across platforms, it won't work (different machines
may use different float formats, and this would still have endianness
issues).


-- 
  finger for GPG public key.

Attachment: pgpEBhmIZ34sx.pgp
Description: PGP signature


Reply to: