I have a huge type and I want to make a command that will give an offset and get the member. I can't make a table. I'm looking for a macro or an idea of how to make one.
Generally speaking there isn't an 'opposite' of the offsetof mapping because it isn't
a bijective mapping. If you only have one struct, its type name and the address
of the struct itself plus the type of the member you want you can do it but it's
easier to take the content of the member directly then because you know
everything already.
I don't know what you're trying to do, but reading between the lines of your question suggests that perhaps it would be useful to store your data in an undifferentiate d block of data that you access only through offset and size arguments. It is your responsibility to deal with pointer alignment limitations and endianness in your architecture.
You can provide one access function that copies a structure member by member into the data block; and another access function that goes in the other direction.
I don't recommend you do this unless you have a very good reason. You should explain that reason very clearly in your comments.
Comment