Packing/unpacking binary data in C - doubles, 64 bits
Michael ODonnell
michael.odonnell at comcast.net
Fri Sep 11 11:06:32 EDT 2009
In just the few minutes I had to actually look at that pack2.c I found
several scary sequences of code, so if you're staying your current course
(instead of adopting some of the other recommendations offered here)
you might want to keep on looking or else write your own from scratch.
For example, in unpack() (where f is a pointer-to-float) we see code
like this:
case 'f':
f = va_arg( ap, float * ); // WTF?
pf = unpacki32( buf );
buf += 4;
*f = unpack754_32( pf ); // Aaieeee!!
break;
...and in main() we see him squirt some data into buf[] and then
immediately overwrite part of it "for kicks":
packetsize = pack(buf, "chhlsf", 'B', 0, 37, -5, s, -3490.6677);
packi16(buf+1, packetsize); // store packet size in packet for kicks
These aren't the droids you're looking for...
More information about the gnhlug-discuss
mailing list