address of register variable

This is a discussion on address of register variable within the C Programming forums, part of the General Programming Boards category; what (address of ) operator should we use to view address of register variables?...

  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,198
    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%.

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

  4. #4
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,616
    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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,424
    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
    1,616
    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
    1,616
    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
    1,616
    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
    21,409
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    1,616
    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
    21,409
    Quote Originally Posted by Sipher
    But can a compiler refuse?
    Yes, since it is technically illegal.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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.

Page 1 of 2 12 LastLast
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, 12: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, 06: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, 08:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21