Thread: Register variable storage

  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    2

    Unhappy Register variable storage

    Why it's not possible to get the address of register variable? if i am right, it must be kept/stored somewhere during run time.

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    A register doesn't have an address, if we mean the same thing...
    Devoted my life to programming...

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by onlynishant
    Why it's not possible to get the address of register variable? if i am right, it must be kept/stored somewhere during run time.
    If the compiler takes your hint and does use a register, then it is not possible to get the memory address simply because it doesn't have one.
    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

  4. #4
    Registered User ledow's Avatar
    Join Date
    Dec 2011
    Posts
    435
    But, to be honest, I don't think ANYBODY uses register variables any more. The compiler is much smarter than you with regards to register use, and even in things like the Linux kernel they don't bother.

    So the solution to your "problem" of not being able to take their address is just to not declare them 'register' at all. You won't notice any difference, but will be able to take their address, and the compiler will still put them in a register for speed if it thinks it can do so.

    - Compiler warnings are like "Bridge Out Ahead" warnings. DON'T just ignore them.
    - A compiler error is something SO stupid that the compiler genuinely can't carry on with its job. A compiler warning is the compiler saying "Well, that's bloody stupid but if you WANT to ignore me..." and carrying on.
    - The best debugging tool in the world is a bunch of printf()'s for everything important around the bits you think might be wrong.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. address of register variable
    By siperi in forum C Programming
    Replies: 15
    Last Post: 11-08-2010, 02:26 PM
  2. variable stored in register or not ???
    By dhondi in forum C Programming
    Replies: 3
    Last Post: 11-03-2009, 01:03 PM
  3. Register variable
    By karthigayan in forum C Programming
    Replies: 2
    Last Post: 05-30-2009, 03:41 AM
  4. Register variable
    By Lettin03 in forum C Programming
    Replies: 2
    Last Post: 11-20-2007, 06:14 AM
  5. Register variable... where are you?
    By pollopinolo in forum C Programming
    Replies: 7
    Last Post: 12-28-2005, 09:09 AM

Tags for this Thread