cpp-ru / ideas

Идеи по улучшению языка C++ для обсуждения
https://cpp-ru.github.io/proposals
Creative Commons Zero v1.0 Universal
89 stars 0 forks source link

Deal with the mess around the "volatile" modifier #502

Closed AVI-crak closed 2 years ago

AVI-crak commented 2 years ago

For x86, "volatile" behavior is considered normal. All data is stored on the stack and external memory, any change obliges to rewrite the variables where they are - on the stack and external memory. For ARM, it's a mess. Data can be stored in registers, on the stack, in external memory, and in memory at a fixed address. But the intermediate unconditional saving to the stack is still used. This point is very relevant for embedded systems, where the memory size can be 4k (very small chip).

I propose to change the attributes of the register space of ARM systems to "fast memory", at least in the form of a crutch for external variable modifiers. In this case, the place of creation and primary placement of a variable with the "volatile" attribute will lose the relevance of unconditional storage on the stack. But it will retain the unconditional execution of any mathematical and logical operations on a variable in the order of writing the program code, until the moment the function is out of scope. The loss of visibility outside the function to store on the stack and in a register is the same, then why pay more?

apolukhin commented 2 years ago

not a C++ standard related idea