what (address of ) operator should we use to view address of register variables?
what (address of ) operator should we use to view address of register variables?
There is none. Computing address of a register variable is not allowed.
For doing that you need to morph into a microchip
Devoted my life to programming...
The register keyword is merely a suggestion to the compiler, however. And there is no reason the compiler wouldn't be able to fetch the value from the register into a memory area and then take the address. Not feasible, I suppose, but still possible.
I think the description that it isn't possible is a better one.
Yeah, the truth is that if you declared a variable as register and later on you asked for its address, the compiler wouldn't make that variable a register, in order to be able to fetch that address later.
Devoted my life to programming...
It's impossible to fetch a register address.
Not quite:
Also, the compiler won't move register variables around if you request a register's address, because there is no mechanism to honor that request.The register keyword is merely a suggestion to the compiler, however. And there is no reason the compiler wouldn't be able to fetch the value from the register into a memory area and then take the address.
It's what i said earlier: If you ask for the address of a declared register in C/C++ the compiler will certainly not make it a register.
Devoted my life to programming...
Or, the compiler can simply refuse to compile the program, which I consider the right thing to do.Originally Posted by Sipher
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
But can a compiler refuse? I've never encountered that!
Devoted my life to programming...
Yes, since it is technically illegal.Originally Posted by Sipher
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Why is anyone using the register keyword anyway? Modern compilers are either going to a) ignore it or b) listen to you and probably generate slower code because you aren't nearly as smart as the compiler is.
And as usual, grumpy's response is correct.