How to give a run time struct definition
-
I want to generate a struct variable whose fields are determined at the run time. It could be one with 2 fields or one with 2000 different fields. For example, During one execution the requirement could be- struct { char[30] name; int salary; float age; } And during another execution it could be- struct { double a[100]; float b; long c[200]; int d; char e; } I'll be very grateful if somebody could help me out.:confused: Gaurav Gumber
-
I want to generate a struct variable whose fields are determined at the run time. It could be one with 2 fields or one with 2000 different fields. For example, During one execution the requirement could be- struct { char[30] name; int salary; float age; } And during another execution it could be- struct { double a[100]; float b; long c[200]; int d; char e; } I'll be very grateful if somebody could help me out.:confused: Gaurav Gumber
You could use a union: union my_union_t { struct { char[30] name; int salary; float age; } struct { double a[100]; float b; long c[200]; int d; char e; } }; you'd have to fill the union with all possible configurations, so it's not really at run time, but I'm not really sure that's possible.