Is the register keyword still used?

前端 未结 6 1261
耶瑟儿~
耶瑟儿~ 2020-12-03 11:54

Just came across the register keyword in C++ and I wondered as this seems a good idea (keeping certain variables in a register) surely the compiler does this by default?

6条回答
  •  被撕碎了的回忆
    2020-12-03 12:35

    Probably the only remotely serious use for the register keyword left is a GCC extension that allows you to use a hard-coded hardware register without inline assembly:

    register int* foo asm("a5");
    

    This will mean that any access to foo will affect the CPU register a5.

    This extension of course has little use outside of very low-level code.

提交回复
热议问题