0

We use C++ in both front-end (Windows 32-bit) and back-end (Linux 64-bit). They can pass either binary or text data to communicate. Is there any middleware/library that will convert these data from 64-bit to 32-bit? Or is the only option to change your code?

phuclv
  • 27,258
  • 11
  • 104
  • 360

1 Answers1

1

There's no such thing like "64-bit text data". A text file just contains characters in some encoding. And currently there's no 64-bit encoding available. The longest fixed-width encoding is UTF-32 which is 32-bit long. For variable-length encoding, it's maximum 6-byte long for UTF-8 (edit: it has been officially limited to 4 bytes only because the range for Unicode was restricted to U+10FFFF) and a different number for others, but none is up to 8 bytes long. If there are differences then you need to convert the encoding, not 64-bit to 32-bit

For more information read The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)


Binary is also just a series of bits, not necessary an array of constant width 64-bit or 32-bit numbers although in modern computer architectures the size is a multiple of bytes. You need to read the data exactly like how they were written. If you write a 64-bit value, read as a 64-bit value regardless of the 16, 32 or 64-bit program. How can you ensure that a number written in 64-bit does not overflow when cropping to 32-bit?

If you're using MSVC then the type sizes are the same in both 32 and 64-bit mode except pointers, thus no code changing is required if you stick to the standard. On most other 64-bit platforms you may need to take care if you use long since it's wider than in a 32-bit program.

It's better to use C++11's standard types like intN_t in cstdint in cross-platform code. Before C++11 and C99 many libraries and compilers also define their own standard fixed-width integer types like that for compatibility, for example qint32 in Qt and __int32 in MSVC

phuclv
  • 27,258
  • 11
  • 104
  • 360
  • Ah yes no need to do anything for text. It's only when you receive that text data and parse each element that is the problem. We need to make sure that no long type data(64-bit linux) is truncated when it is received in 32-bit windows especially when dealing with structures. Any third party library/middleware that can convert this for you? If none then we just change the code. – Mark Gabriel A. Paylaga Dec 06 '13 at 06:19