variables

This is a discussion on variables within the C Programming forums, part of the General Programming Boards category; Hi, When you declare a variable such as int length, does the identifier part (length) hold the actual address and ...

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    1

    variables

    Hi,

    When you declare a variable such as int length, does the identifier part (length) hold the actual address and when you assign say: length =5 then the identifier is deferenced? or is this incorrect what im assuming?

    thank you

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    I am not a compiler expert, so someone will probably come along and correct me, but: The compiler can do it any way it wants to, as far as I understand the C standard.

    When you do length = 5, the 5 has to be put somewhere in memory, that is true. I would expect that memory location to be found by the compiler via a look-up table, which may or may not fit your notion of "dereferenced".

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,264
    I'd say tabstop is right. If the compiler can prove that in fact length is effectively a constant, it may even be able to simply remove the length variable and replace it with the constant value.
    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

  4. #4
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,832
    The compiler builds a symbol table which holds variable names. It looks up any uses of variables and builds the memory addresses right into the resultant code. In the finished code, unless symbolic information is kept for a run-time debugger, the variable names are not saved anywhere. If an executable consists of multiple C modules that share variables then symbol information is saved in the .obj's until the linker makes use of them to tie things together. In the end they are discarded also.

    joe345 makes correct assumptions as to how one can think of how things work, conceptually. In keeping with C nomenclature of address, dereferencing, etc. How things work in practice in the interest of code speed, computer hardware utilization, things may be implemented differently.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with Accessing Variables
    By vileoxidation in forum C++ Programming
    Replies: 10
    Last Post: 10-05-2009, 08:58 AM
  2. Protected / Private Variables accessable.
    By +Azazel+ in forum C++ Programming
    Replies: 19
    Last Post: 09-08-2009, 08:39 PM
  3. Question about Static variables and functions.
    By RealityFusion in forum C++ Programming
    Replies: 2
    Last Post: 10-14-2005, 03:31 PM
  4. Remotely Creating Variables
    By Rajin in forum C++ Programming
    Replies: 1
    Last Post: 04-27-2005, 12:20 AM
  5. Declaring an variable number of variables
    By Decrypt in forum C++ Programming
    Replies: 8
    Last Post: 02-27-2005, 04:46 PM

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