There is no such thing in C.
You would have to write your own code to solve that. How you would do that and what the best solution is, depends a little bit on what your structur(es) look like and what your application needs to do.
You can't really use switch either.
Here's a solution that may work:
Code:
struct somestruct
{
int x;
int y;
int z;
};
struct propentry
{
ptrdiff_t offset;
const char *name;
};
#define PE(a) { offsetof(somestruct, a), #a }
struct propentry proptable[] =
{
PE(x),
PE(y),
PE(z)
};
int getProperty(char *name, somestruct *astruct)
{
int i;
for(i = 0; i < sizeof(proptable)/sizeof(proptable[0]); i++)
{
if (strcmp(proptable[i].name, name) == 0)
{
int *ptr = (int *)(((char *)astruct) + proptable[i].offset);
return *ptr;
}
}
return -1;
}
I haven't tried to compile the code, so it may not work 100% straight out of the box, but it's showing the principle fairly well.
It gets even more complicated if the content is not all integers, of course...
--
Mats