[PD-dev] Bit fields in t_editor

Martin Peach chakekatzil at gmail.com
Fri Feb 14 03:54:29 CET 2020


On Thu, Feb 13, 2020 at 9:24 PM Henri Augusto Bisognini
<msndohenri at hotmail.com> wrote:
>
> Quick C question: i was taking a look at struct _editor and I've noticed that the bitfields sum up to  6 with no (2 bits) padding for alignment.
>
> typedef struct _editor
> {
>     t_updateheader e_upd;           /* update header structure */
>     [...]
>     unsigned int e_onmotion: 3;     /* action to take on motion */
>     unsigned int e_lastmoved: 1;    /* one if mouse has moved since click */
>     unsigned int e_textdirty: 1;    /* one if e_textedfor has changed */
>     unsigned int e_selectedline: 1; /* one if a line is selected */
>     t_clock *e_clock;               /* clock to filter GUI move messages */
>     int e_xnew;                     /* xpos for next move event */
>     [...]
>
> } t_editor;
>
>
> All the resources I've found on google used some padding (either manually or with a zero value).
>
> My guess here is that since the next member is not a bit field then the compiler will align it for you. Is that right?

They are all unsigned ints with some of their bits used, so they are
aligned already to whatever bit-size ints are.

Martin





More information about the Pd-dev mailing list