Will this trick work in C?

后端 未结 5 964
终归单人心
终归单人心 2021-01-21 15:50

I want to add a field to a structure in C. So for example I have the following structure.

struct A
{
 some_type x;
 some_type y;
}

I declare a

5条回答
  •  温柔的废话
    2021-01-21 16:55

    Yes, it is valid. Word of the Standard, C99 6.7.2.1/13:

    ... A pointer to a structure object, suitably converted, points to its initial member (or if that member is a bit-field, then to the unit in which it resides), and vice versa. There may be unnamed padding within a structure object, but not at its beginning.

提交回复
热议问题