+ 10
Is it possible to define structure at runtime?
I want to do this in C language . Give complete description about what you think . Thanks.🤗
10 Antworten
+ 3
but what you are attempting to do is basically impossible, you could ask the user to give you a dictionary of types and names, but you would have to reserve the space manually with malloc, then save a pointer to that space then write the content of those variables in that region and then get them back by using the pointer and adding all the space to it that the variables that come first take up. the basis of your programm would then be a struct that looks like
struct LiveStruct{
char* name;
LinkedListOfTuples* lkt;
void* memoryregion;
}
where
struct LinkedListOfTuples {
LinkedListOfTuples* next;
char* name;
char* type;
}
and you would use the linked list to navigate the memory region since it gives you the types.
generalizing this in a way that lets users use usersefined structs inside userdefinied structs would be even more painful and would require you to track all userdefined structs
but that would be a lot of overhead
+ 8
that's ok dear I just want others opinion.🤗
+ 8
to have some fun in coding
+ 7
I have already checked on stackoverflow🤗
+ 7
plz give your own opinion
+ 7
I don't want to define structure before running the code, user will tell what types of variables he/ she want
+ 3
hope this is what you wanted
https://bytes.com/topic/c/answers/222974-runtime-structure
+ 3
ok why exactly do you need to define it at runtime
+ 1
what do you mean by define structure on runtime? you can‘t edit the code after the program has compiled
+ 1
it may be possible are you into c?