There is no “special rule” for register used in conjunction with void * , register will work on void * as with any variable, suggesting to the compiler that such a variable will be heavily used and that it should be placed in the CPU register.
However, in principle, there is no reason to use register anywhere, since the optimizers included in current compilers are much better than programmers, guessing which variables should fit in registers, and will almost always happily ignore the register keyword completely.
The C99 standard also contains some additional information about register (§6.7.1 ¶4):
Declaring an identifier for an object with a register storage class specifier implies that access to the object should be as fast as possible. The extent to which such proposals are effective is determined upon implementation. 101)
101) An implementation can consider any register declaration simply as an auto declaration. However, regardless of whether address storage is actually used, the address of any part of an object declared with the storage class specifier register cannot be calculated explicitly (using the unary & operator, as described in 6.5.3.2), or implicitly (by name conversion array to pointer, as described in 6.3.2.1). Thus, the only statement that can be applied to an array declared using the register storage class specifier is sizeof .
Thus, using register , you are likely to get only the shortcomings of pretending to be variables in the register. :) Please note that the C ++ standard eases these restrictions, but obviously, if you try to take the address of the register variable, it will no longer remain in register.
In short, register is basically like a relic of the past, avoiding this is the best thing you can do with it. :)
Matteo italia
source share