Since we're talking about history, I'm referencing the C89 standard...
Originally Posted by
C89 3.5.1
A declaration of an identifier for an object with storage-class specifier register suggests that access to the object be as fast as possible. The extent to which such suggestions are effective is implementation-defined. (49)
Originally Posted by
nonoob
I don't think so. In the days where 'register' did what it was claimed to do, up to a maximum of two such uses as I recall, the program did in fact improve performance.
register still "does what it's supposed to do", which is suggest the compiler make it as fast as possible. The limit of how many register variables you could use effectively was architecture dependent. The SPARC architecture used by Sun had 8 global general purpose registers and 8 local general purpose registers per frame (they had a sexy sliding-frame setup for function calls). The compiler could possibly put 16+ variables in registers.
If there were oddball address aliasing, the compiler would have noticed it and provided sufficient code to propagate the value into real RAM (from the register) as required. Unless you can point to specific compilers which had known bugs in this regard.
Determining the address of a register variable is expressly prohibited, which makes perfect sense since it might not be in memory and thus has no address:
Originally Posted by
C89 standard footnote 49
The implementation may treat any register declaration simply as an auto declaration. However, whether or not addressable storage is actually used, the address of any part of an object declared with storage-class specifier register may not be computed, either explicitly (by use of the unary & operator as discussed in 3.3.3.2) or implicitly (by converting an array name to a pointer as discussed in 3.2.2.1). Thus the only operator that can be applied to an array declared with storage-class specifier register is sizeof .
As an aside, could you compile your example Tater? What compiler are you using? GCC wouldn't let me...
The reference book that was referred to may be out-of-date with today's much more optimizing compilers. Perhaps the keyword 'register' has just been left over for backward compatibility...
Doubtful. Compiler writers are pretty awesome coders and their optimizations are generally much faster, but not knowing the intent of your code, they can only optimize so much. It's quite possible that you have some intricate knowledge of your algorithm and know you want a specific variable in a register, thus I would wager most decent compilers do their darnedest to honor the keyword, assuming that if you use it, you know what you're doing. Indeed, GCC (v4.4.4) translated the following two declarations differently:
Code:
// foo.c
#include <stdio.h>
int main(void)
{
int x = 5;
register int y = 10;
printf("x: %d\n", x);
printf("y: %d\n", y);
return 0;
}
gcc -S foo.c
Code:
movl $5, 28(%esp) ; this is x, referenced from the stack pointer
movl $10, %ebx ; this is y, stored directly in a register