Potential issues with porting to different architectures

I am writing a Linux program that currently compiles and works fine on x86 and x86_64, and now I am wondering if there is anything special that I need to do to make it work on other architectures.

I heard that for cross platform code I have to:

  • Don't assume anything about pointer size, int or size_t
  • Do not make assumptions about byte order (I do not perform any bit offsets - I assume gcc optimizes my strength for two multiplications / divisions for me)
  • Do not use mounting blocks (obviously)
  • Make sure your libraries work (I use SQLite, libcurl and Boost, which seem pretty cross-platform)

Is there anything else I need to worry about? I am not currently targeting any other architectures, but at some point I expect ARM support, and I believe that I could also get him to work on any architecture if I can.

Also, as for my second question about byte order, do I need to do something with text input? I am reading files with getline() , so it seems like this should also be done automatically.

+4
source share
1 answer

In my experience, when code works well on multiple architectures, it will be easier to port to the third. Typing should not be a problem. Aligning the structure can be a problem if you do anything when the alignment problem is a problem.

Pay attention to everything that may be platform dependent: relying on bit field alignment in the same way, assuming the variables are a specific size, etc. If your code is relatively abstract from hardware, you are likely to run into small problems. If you are doing something with something like network code, you need to make sure that you are ordering the network byte order correctly.

I ported device drivers from PPC to x86, and then to x86_64; in a few thousand lines, perhaps a couple of changes have occurred, primarily related to the structure and the whole order.

The only way to know for sure is to try it, of course.

+3
source

Source: https://habr.com/ru/post/1307611/


All Articles