On Wed, 19 Nov 2025, Qing Zhao wrote:
> Hi,
>
> For the following two cases:
>
> A. Anonymous structure type is a top-level type:
>
> struct {
> int a;
> char c[] __attribute__ ((counted_by (a)));
> };
>
> B. Anonymous structure type is the type for an unnamed field of another
> structure:
>
> struct s {
> int a;
> struct {
> int b;
> char c[] __attribute__ ((counted_by (a)));
> };
> };
>
>
> My question:
>
> When C FE sees the above two anonymous structure type in A and B, how to
> distinguish them?
That's not the right distinction to make, since you can modify B
struct s {
int a;
struct {
int b;
char c[] __attribute__ ((counted_by (a)));
} x;
};
and adding the name to the field means it no longer has any of the special
effects on name lookup.
The logic that determines whether a particular unnamed field declaration
is valid as an anonymous struct / union (with the associated special
properties) is in grokfield. This is not a property of the anonymous
struct / union itself, but of how it is used when declaring a field of an
outer struct / union.
--
Joseph S. Myers
[email protected]