How much bad can be done using register variables in C++

前端 未结 7 2334
孤城傲影
孤城傲影 2021-02-18 17:07

I just came to know that we can use registers, explicitly in C++ programs. I wonder what if i declare and use all available registers in a single C++ program and run it for cons

7条回答
  •  粉色の甜心
    2021-02-18 17:40

    Only specific number of Registers are available for your C++ program.

    Also, it is just a suggestion for the compiler mostly compilers can do this optimization themselves so there is not really much use of using register keyword more because compilers may or may not follow the suggestion.

    So the only thing register keyword does with modern compilers is prevent you from using & to take the address of the variable.

    To Quote Herb Sutter on this:
    Never write register. It's exactly as meaningful as whitespace

提交回复
热议问题