Thread: Printing all the variable names in a program.

  1. #1
    Registered User
    Join Date
    Mar 2009

    Question Printing all the variable names in a program.

    I want to write a program that will print all the variable names used in that code. Just like "who" in MATLAB prints all the variables used in the program.
    Please guide me a bit.

  2. #2
    Registered User Swarvy's Avatar
    Join Date
    Apr 2008
    United Kingdom
    I'm no expert on this topic, but to the best of my knowledge, when you write C/C++ code the name of the variables are 'superficial', what I mean by that is that the names are used by the compiler as a means to make it easier for the programmer to write/read the code. The computer doesn't see the names of the variables you give, but instead simply sees a series of memory addresses, pointers etc. The reason why you can see the variable names in matlab is because matlab scripts don't interface with the OS but instead run through a virtual machine (similar to how the java virtual machine works).

    You could try to set up a structure for a given variable and within the structure you have different attributes, one of these could be the variable name you've specified. I don't really see the point of a program which spits out the names of the variables you've specified unless you go all the way and design your own scriptable language, but maybe that is your intention, I don't know.

    Like I said, I'm no expert, but to the best of my knowledge that is how this stuff works. If someone corrects me, then I'll be learning too

  3. #3
    Registered User
    Join Date
    Aug 2010
    Do you know what you want to do?
    You can't do anything like that on runtime or in compile time. C++ is not a scripting language!
    If you want to get a list of all the variables (all the symbols) you need to compile your progam with debugging options turned on, and then, using appropriate tools/debugger acquire the list of all symbols.
    Last edited by kmdv; 09-29-2010 at 09:46 AM.

  4. #4
    Join Date
    Oct 2007
    Inside my computer
    What does that have to do with the topic?
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  2. program printing ".N=?" at beginning of string
    By bertazoid in forum C Programming
    Replies: 22
    Last Post: 02-10-2009, 12:14 PM
  3. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  4. Question about printing a variable???
    By Hoser83 in forum C++ Programming
    Replies: 2
    Last Post: 03-31-2006, 01:57 PM
  5. Variable Allocation in a simple operating system
    By awkeller in forum C Programming
    Replies: 1
    Last Post: 12-08-2001, 02:26 PM