create vars from string while program is running


i am creating a program that needs to CREATE a variable while the arduino is running.
so when the arduino is running with my program it needs to be able to do for example:

int (name from string)[/code
so if string1 has value: "hello" and then i do[code] int string1= 5

it needs to create a var with as name hello and as value 5.
this isnt possible by just doing

int string1 = 5

so what is the right way to do this?

can anyone help my?


You may think you need to do that, but you probably don't. What do you need it for?

You can not create a variable while the program is running. The process for creating a variable involves declaring a type, which defines how much memory to allocate, actually allocating the memory, and adding the name and address to two tables that are used throughout the compilation process.

Once compilation is complete, names no longer exist.

As aarg does, I suspect that this is an XY problem, where you want to do one thing but think you need to do something else.

You need to explain why you think that dynamically defining variables is needed. There ARE ways to accomplish what you want, but you would need to use malloc() or new AND you would have to perform your own name to address mapping if you expect to use that variable elsewhere.

i need it for my own basic interpreter.
the interpreter can have variables and i need to save them in the memmory.
so in my basic program i do varname = 6
and then it needs to save that in its memmory.
and when i do drawline varname 8 5 7 blue
it needs to change varname with 6.

what is the best way to save the var in its memory?
and how do i read it then back?


what is the best way to save the var in its memory?

Create a dictionary, with name = value pairs. When you are told to create or update a name = value pair, create or update the dictionary entry. When you are told to use a name's value, access the dictionary to get the value of the appropriate name=value pair.

Frankly, if you need to ask such a basic question, you are miles away from being able to write an interpreter.