data is transfered over IP from a 32-bit machine to a 64-bit machine (or vice versa). Since the data will be transfered in network byte order there will be no problem during the transfer. Question: Will there be any problem when the data reaches the receiving end? What should be taken care of to avoid any problems, if there are any?
Not an issue... data is generally stored (and transfered) as bytes, the size of which is generally 8 bits, and is not dependent on whether the architecture is 32-bit or 64-bit.
The "32-bit" or "64-bit" part of a system specification generally refers to two things: the size of is addresses (for pointers to memory) and the size of its registers (for on-CPU computation). This has no impact on actual data, whether stored on disk or sent over the network.
At the level of abstraction you are talking about, there should be no problem. 32 vs 64 will not affect network communication at the socket level.
I think the question has been misunderstood by the previous two answerers. The OP's comments indicate that they are transferring a long
from an LP64 system to an ILP32 system, presumably both x86.
On an LP64 x86 system, the long
primitive type is 64 bits wide, least significant byte first. On an ILP32 x86 system, the same long
primitive type is 32 bits wide, least significant byte first.
Problems will arise if you naively code with the long
datatype and transfer numbers to and fro. You might be debugging on your x86_64 development PC and everything seems to work (with you memcpy()ing everything) and it breaks in mysterious ways on an i386 system because you're trying to squeeze 8 bytes into a 4-byte long
.
This is why stdint.h
was introduced in the C99 standard library. It allows you to write more portable code by specifying precise widths for your integers. If you want a 64-bit wide unsigned integer, use uint64_t
. This type is invariant across ILP32 and LP64 x86 systems. Likewise, if you want a 32-bit wide signed integer, use int32_t
. See this article on Wikipedia for much more information on the topic.