Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Struct#address_of(field) method? #596

Open
chuckremes opened this issue Dec 22, 2017 · 0 comments
Open

Add Struct#address_of(field) method? #596

chuckremes opened this issue Dec 22, 2017 · 0 comments

Comments

@chuckremes
Copy link

I recently ran into an issue where I needed to pass the address of a Struct's field to a function (see inet_ntop(3)). I ended up having to base the base address of the struct into a Pointer and calculate the field's address using the offset. This isn't hard but it does seem like a reasonable enhancement to the Struct class.

Question: would a patch/PR implementing Struct#address_of(field) be accepted? It would essentially look like this (with specs):

  def address_of(field)
    Pointer.new(:uint8, self.pointer.address + offset_of(field.to_sym))
  end

Feedback?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant