Is there an opposite to "offsetof" ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • LittleG
    New Member
    • Oct 2008
    • 1

    Is there an opposite to "offsetof" ?

    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.

    Thanks
    LittleG
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    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.

    kind regards,

    Jos

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #3
      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

      Working...