Quote:
Originally posted by kev82
i was gonna suggest that but the only functions are htons(),ntohs() - 16bit and htonl(),ntohl() - 32bit and a double is 64bit so i dont think they work, they are supported in windows though.
|
You're exchanging data with a Java program right? In Java a byte is 8 bits, a short is 16 bits, an int is 32 bits, a long is 64 bits, a float is 32 bits, and a double is 64 bits.
Passing around byte, short, int, and long won't be a problem (as long as you get the bit order correct and the number of bits in each type matches on both the client and server) because everyone uses two's complement representation of integer values. You'll have to do some translation if the size of each type is different on the client and server.
Float and double values are a different story. Different architectures represent floating point numbers in different ways. There are a bunch of different standards, and the Sun Java Specification does not require a JVM to use a specific format. So, when dealing with floating point numbers you have three things to worry about
:
1. Variable size
2. Bit order
3. Floating point representation (i.e. which bits represent the mantissa, sign, and exponent).
The Java Specification may have something in it about how JVMs must transmit floating point values over a network connection, so you may want to look into that. If it does, then you know that you'll need to translate between whatever format your C++ client uses to the format that the JVM expects. Of course, that means your client isn't cross-platform.