A
A
artemphrog2020-12-02 15:18:12
C++ / C#
artemphrog, 2020-12-02 15:18:12

Range of C++ data types?

The range of some data types depends on the architecture of the processor and compiler. I have a question. Suppose while writing a program, my architecture supports 4 bytes under int, and variables with this type and values ​​\u200b\u200bare defined for 4 bits, and the processor architecture for the user of my program supports only 2 bytes. Can this cause a program error for the user? Or is that not how it works?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Shatunov, 2020-12-02
@artemphrog

I would like to recommend you material from PVS-Studio developers regarding data models in C++ . There is a good and short explanation of the essence of your question.
It will also be useful for you to study the C ++ documentation , where you can learn the details.
The data model is selected during translation and cannot be changed in the already assembled binary code. Absolutely all binary code relies on the values ​​of the data model literally at every moment of execution. Changing the data model of a binary code will require a detailed analysis of both the executable code and all the memory structures that the binary code operates on. This will be equivalent to retranslating the source code into binary with a different data model.
The data model is strongly connected not only with the binary code of the application itself, but also with its dependencies on system libraries. A process with the wrong data model will not be able to work properly with system libraries simply because the system and the process treat data in memory differently.
Therefore, in a general sense, your question can be answered as follows. If the client system expects one data model from the process, and it works in another, then the process cannot be avoided. In some cases, the process will not even be loaded into memory, because. the binary code loader can indirectly determine the incompatibility of the process and system at the client.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question