I am writing a compiler that compiles a language that has similar concepts to C to byte code which should then be interpreted by a corresponding stack-based VM. I am stuck at the moment when it comes how to compile structs, e.g.
struct my_struct_s {
int anInt;
char* aString;
} my_struct_t;
/* ... */
my_struct_t my_struct_var;
Where should I best put the my_struct_var in the byte code? How do C compilers handle such stuff? Later on, the VM also must handle the memory needed to represent this struct var, since it should be write- and reabable.
Where would you put this kind of variable? Onto the stack? Just put the memory address of this var onto the stack?
Thanks, Jonas