Thread: address of register variable

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    32

    Lightbulb address of register variable

    what (address of ) operator should we use to view address of register variables?

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    There is none. Computing address of a register variable is not allowed.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    For doing that you need to morph into a microchip

  4. #4
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    Quote Originally Posted by grumpy View Post
    Computing address of a register variable is not allowed.
    It's not just that. Computing address of a register variable, if the compiler decides to obey your request, is impossible! Registers are CPU variables, they're not located in memory.
    So i agree more with your first statement:
    Quote Originally Posted by grumpy View Post
    There is none.
    Devoted my life to programming...

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    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...

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    It's impossible to fetch a register address.

  8. #8
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    Quote Originally Posted by Adak View Post
    It's impossible to fetch a register address.
    ... Didn't we just say that? ...
    Devoted my life to programming...

  9. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Not quite:
    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.
    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.

  10. #10
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    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...

  11. #11
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Sipher
    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.
    Or, the compiler can simply refuse to compile the program, which I consider the right thing to do.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  12. #12
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    But can a compiler refuse? I've never encountered that!
    Devoted my life to programming...

  13. #13
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Sipher
    But can a compiler refuse?
    Yes, since it is technically illegal.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  14. #14
    Registered User Char*Pntr's Avatar
    Join Date
    Sep 2007
    Location
    Lathrop, CA
    Posts
    198
    Quote Originally Posted by grumpy View Post
    There is none. Computing address of a register variable is not allowed.
    Since this, it seems, is going to turn into a 5+ page thread anyway, I completely agree with what Grumpy had to say. When I first read the reply, I thought that would be the end of that.

  15. #15
    Registered User
    Join Date
    Mar 2009
    Posts
    344
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. variable stored in register or not ???
    By dhondi in forum C Programming
    Replies: 3
    Last Post: 11-03-2009, 01:03 PM
  2. urgent! variable address
    By sasuke_0214 in forum C Programming
    Replies: 8
    Last Post: 05-08-2009, 01:09 PM
  3. DX - CreateDevice - D3DERR_INVALIDCALL
    By Tonto in forum Game Programming
    Replies: 3
    Last Post: 12-01-2006, 07:17 PM
  4. may address of a variable be null
    By hebele in forum C Programming
    Replies: 5
    Last Post: 07-01-2005, 02:16 PM
  5. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM