I am trying to build a constructor-like function for structs in C. I'm best with languages built around object-oriented features, and adding object-oriented features to a bare-bones language is not my forte. Unfortunately, for this project, however, I am forced to use a variation of C.
The idea is to build a function with a parameter for each variable in the struct that needs to be initialized, along with a 'name' parameter for the name of the struct.
The biggest issue is that the variation of C I need to use is very limited in features. It doesn't seem to have dynamic memory allocation, among other things.
The goal code would be something like this:
typedef struct {
int a;
string b;
} TheStruct;
void newStruct(string name, int a, string b){
TheStruct name;
name.a = a;
name.b = b;
}
This won't work, because the struct instantiated with be called 'name' rather than the value of the name variable. How, without using higher-level features not found in C like variable variables, could a struct be dynamically referenced this way in C?