Name variable with contents of a variable

Hi This is a bit of an obscure question and I wouldn't be surprised if its not possible to do. It isn't Arduino specific, more of a C question. Anyway, my question is this: is it possible to name a new variable (eg int) with the contents of another? For example (not sure if the syntax is correct but you get my point): char myWord[] = {"myInt"}; int myWord; //referring to the actual contents of myWord, not the literal letters "myWord"

Now there's the problem. The compiler would then say "you are declaring it twice" and it wouldn't work. But what I really mean is the name the new int variable with the contents of the variable myWord, and the name of the int would be "myInt". Is this possible? Thanks

No, it isn't possible. C is a compiled language.

What do you think you want to do, rather than how you think you want to do it?

Thanks for the quick reply.
As I thought, unfortunately. What I was thinking of was runtime variable creation based on user input.
However, I was mainly just wondering if it was possible.

What I was thinking of was runtime variable creation based on user input.

What would that achieve that cannot be done in other ways ?

If you want to reuse memore can maybe use an union type union myWord { char *smyword; int imyword; }

http://en.wikipedia.org/wiki/Union_type

UKHeliBob:

What I was thinking of was runtime variable creation based on user input.

What would that achieve that cannot be done in other ways ?

No I realise it has no practical purpose, I was simply wondering if it was possible. And sometimes it is nice to do something even if it has no real value. And no I wasn't thinking about memory either, but thanks for the suggestion (I might have to use that the amount of times i run out of RAM).

You can create a list of variables, containing a string to "name" the variable, and somewhere to record its value, but it seems a bit wasteful.

You can do it statically using the pre-processor, but that would not solve your problem of allowing the user to name variables, and you would still need to deal with all the parsing and name lookup. I suspect what you really want here is something more like a command line interpreter such as bitlash, but without knowing what you're trying to achieve I can't say whether you need something that complicated. For small applications, it is probably more sensible just to parse the 'variable name' out of the serial input and then compare that against a hard-coded list of names supported by your sketch and access the corresponding variable directly.

if(strcmp(name, "foo") == 0)
{
   // do something to variable foo
}
else if (strcmp(name, "bar") == 0) ...

You get the idea.