Declaring Variables Using Variables

This is a discussion on Declaring Variables Using Variables within the Windows Programming forums, part of the Platform Specific Boards category; how could I declare a variable by naming it with another variable. For example. I want the name of "int ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    5

    Declaring Variables Using Variables

    how could I declare a variable by naming it with another variable. For example.

    I want the name of "int x" to be the value of "char* x".

    This possible?

  2. #2
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    523
    If I get what you mean you can put int x in char *x like so
    Code:
    char *x = "int x";
    but if you mean you want to use int x as a variable name you can't because you cant have a space in a variable name and using keywords as variable names is illegal also, you would have to use an underscore: int_x.
    Why would you want to do this anyway?
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  3. #3
    Mr.Squirrel
    Guest
    No, what I meant was:

    char* name = "variable_name";
    int name;
    //The int is actually called int variable_name

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    You want to name, or change the name, of a variable AFTER the exe is built?

    As far as I know, not possible.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Unregistered
    Guest
    There is a slight possibility tho in DLL's. You may be able to modify the dll without the necessity of compilation afterward. However, if it's a DLL you'd have to modify before declaring the DLL in your program, I think...

    But anyway, the real issue here is that this would be a shear novelty program with no use to the developer, really.

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    You can have a config file to get a value and use this.

    ie
    in the config file to be loaded and read at runtime
    ConfigFile.sText[64]="SomeText";

    in a header

    #define MY_TEXT ConfigFile.sText

    so after the program starts

    MY_TEXT = "SomeText"

    But this is not what you realy want
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Declaring variables in int main()?
    By Programmer_P in forum C++ Programming
    Replies: 4
    Last Post: 05-12-2009, 02:21 AM
  2. Declaring Variables
    By Godders_2k in forum C Programming
    Replies: 10
    Last Post: 11-18-2007, 03:50 AM
  3. Declaring variables
    By Marlon in forum C++ Programming
    Replies: 6
    Last Post: 06-21-2005, 04:16 AM
  4. question about declaring global variables
    By Dag_ in forum C++ Programming
    Replies: 2
    Last Post: 04-27-2005, 06:03 AM
  5. Declaring an variable number of variables
    By Decrypt in forum C++ Programming
    Replies: 8
    Last Post: 02-27-2005, 03:46 PM

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