We have a 32-bit C++ GUI application running on 32 bit windows 7. We are planning to migrate our server with C++ apps to 64-bit linux. We have noticed that long types are larger in 64 bit. This will be incompatible with the client-server message passing from 64-bit to 32-bit. What is a good way to solve this incompatibility? Do we need to change the code? How? or Do we use a third party software to do the conversion? What software is it?
Asked
Active
Viewed 1,260 times
1 Answers
3
That's why there is the standardized int32_t
and uint32_t
types etc., so you could specifically select type depending on your needs.
It might be quite a lot of work to replace all long
types to int32_t
in all structures you send, especially if it's a big project, but you (hopefully) only have to do it once. Another way of solving this problem is to serialize the data into a text-format and then deserialize it on the receiving side, this has the big advantage that it will make the communication almost completely platform independent.

Some programmer dude
- 400,186
- 35
- 402
- 621
-
Thanks for your comment. Do you mean to say we need to develop a serializer/deserializer if we dont use the int32_t? Or is there some existing software that can do this for you? – coredumper Dec 05 '13 at 08:04
-
@MarkGabrielA.Paylaga Serialization is overall the best solution, especially if starting from scratch. But it can be hard to work into an existing code-base. There are tools/libraries that can help (see e.g. [Google protobuf](http://code.google.com/p/protobuf/)). However, if you already have an existing (and possibly extensive) code-base it might be easier to continue sending binary structures, but change field types to more portable ones. – Some programmer dude Dec 05 '13 at 08:08
-
Thanks. We are not starting from scratch. We have an extensive code-base. When you serialize a 64-bit long in the 64bit machine and deserialize it in the 32-bit machine there would still be some incompatibility right? The 64bit long data will be truncated and become 32bit? – coredumper Dec 05 '13 at 08:57
-
@MarkGabrielA.Paylaga Only if you have values larger than the max possible with 32 bits. – Some programmer dude Dec 05 '13 at 08:59
-
Yeah that's what I thought. So serializing/deserializing will still not solve the truncating problem if ever the value is larger than the 32 bits. So is it safe to say that it would be better to just change the types to make them compatible with each other? (if I cannot find a library or middleware to fix this). – coredumper Dec 05 '13 at 09:03
-
@MarkGabrielA.Paylaga If you don't plan for it beforehand then yes, changing the type is the best way to go. – Some programmer dude Dec 05 '13 at 09:39