C: Pointers to any type?
- by dragme
I hear that C isn't so type-safe and I think that I could use that as an advantage for my current project.
I'm designing an interpreter with the goal for the VM to be extremely fast, much faster than Ruby and Python, for example.
Now I know that premature optimization "is the root of all evil" but this is rather a conceptual problem.
I have to use some sort of struct to represent all values in my language (from number over string to list and map)
Would the following be possible?
struct Value {
ValueType type;
void* value;
}
I would store the actual values elsewhere, e.g: a separate array for strings and integers, value* would then point to some member in this table.
I would always know the type of the value via the type variable, so there wouldn't be any problems with type errors.
Now:
Is this even possible in terms of syntax and typing?