c++performancecachinglatency

Is the register keyword still used?


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?

So I wondered is this keyword still used?


Solution

  • Most implementations just ignore the register keyword (unless it imposes a syntactical or semantical error).

    The standard also doesn't say that anything must be kept in a register; merely that it's a hint to the implementation that the variable is going to be used very often. Its use is even deprecated.

    7.1.1 Storage class specifiers [dcl.stc]

    3) A register specifier is a hint to the implementation that the variable so declared will be heavily used. [ Note: The hint can be ignored and in most implementations it will be ignored if the address of the variable is taken. This use is deprecated (see D.2). — end note ]