+ 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.đŸ€—

27th May 2018, 2:58 PM
Ananya Srivastava
Ananya Srivastava - avatar
10 Answers
+ 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
28th May 2018, 12:28 PM
Max
Max - avatar
+ 8
that's ok dear I just want others opinion.đŸ€—
27th May 2018, 3:11 PM
Ananya Srivastava
Ananya Srivastava - avatar
+ 8
to have some fun in coding
28th May 2018, 12:14 PM
Ananya Srivastava
Ananya Srivastava - avatar
+ 7
I have already checked on stackoverflowđŸ€—
27th May 2018, 3:06 PM
Ananya Srivastava
Ananya Srivastava - avatar
+ 7
plz give your own opinion
27th May 2018, 3:06 PM
Ananya Srivastava
Ananya Srivastava - avatar
+ 7
I don't want to define structure before running the code, user will tell what types of variables he/ she want
28th May 2018, 5:16 AM
Ananya Srivastava
Ananya Srivastava - avatar
27th May 2018, 4:08 PM
‎ ‏‏‎Anonymous Guy
+ 3
ok why exactly do you need to define it at runtime
28th May 2018, 10:27 AM
‎ ‏‏‎Anonymous Guy
+ 1
what do you mean by define structure on runtime? you can‘t edit the code after the program has compiled
27th May 2018, 3:43 PM
Max
Max - avatar
+ 1
it may be possible are you into c?
21st Jun 2018, 4:55 AM
Buddha Nag
Buddha Nag - avatar