public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* [gcc plugin] get member offset in struct just like offsetof
@ 2018-02-06 15:25 dotpy
  2018-02-06 16:58 ` Eric Botcazou
  0 siblings, 1 reply; 3+ messages in thread
From: dotpy @ 2018-02-06 15:25 UTC (permalink / raw)
  To: gcc

Hi experts,



I am writing a gcc plugin for parsing the structure fields. But I have the problem how to get the offset of each field in the struct? Just like the offsetof macro in gcc.

I see DECL_FIELD_OFFSET in tree.h, but the result seems not right.

My test program could be found in stack overflow:

https://stackoverflow.com/questions/48582971/gcc-plugin-to-implement-offsetof




Could someone explain what is DECL_FIELD_OFFSET used for, and how to implement offsetof?




Thanks

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [gcc plugin] get member offset in struct just like offsetof
  2018-02-06 15:25 [gcc plugin] get member offset in struct just like offsetof dotpy
@ 2018-02-06 16:58 ` Eric Botcazou
  2018-02-07 15:20   ` dotpy
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Botcazou @ 2018-02-06 16:58 UTC (permalink / raw)
  To: dotpy; +Cc: gcc

> I am writing a gcc plugin for parsing the structure fields. But I have the
> problem how to get the offset of each field in the struct? Just like the
> offsetof macro in gcc.
> 
> I see DECL_FIELD_OFFSET in tree.h, but the result seems not right.

The offset in bits/bytes is given by tree.c:bit_position/byte_position.

-- 
Eric Botcazou

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re:Re: [gcc plugin] get member offset in struct just like offsetof
  2018-02-06 16:58 ` Eric Botcazou
@ 2018-02-07 15:20   ` dotpy
  0 siblings, 0 replies; 3+ messages in thread
From: dotpy @ 2018-02-07 15:20 UTC (permalink / raw)
  To: Eric Botcazou; +Cc: gcc

Hi Eric,

Thank you very much. Your advise is exact right. :)
The function bit_position and byte_position is what I want to implement offsetof.

Regards

At 2018-02-07 00:58:17, "Eric Botcazou" <ebotcazou@adacore.com> wrote:
>> I am writing a gcc plugin for parsing the structure fields. But I have the
>> problem how to get the offset of each field in the struct? Just like the
>> offsetof macro in gcc.
>> 
>> I see DECL_FIELD_OFFSET in tree.h, but the result seems not right.
>
>The offset in bits/bytes is given by tree.c:bit_position/byte_position.
>
>-- 
>Eric Botcazou

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-02-07 15:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-06 15:25 [gcc plugin] get member offset in struct just like offsetof dotpy
2018-02-06 16:58 ` Eric Botcazou
2018-02-07 15:20   ` dotpy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).