> On Nov 20, 2025, at 12:40, Joseph Myers <[email protected]> wrote:
> 
> 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.

As Martin mentioned before,  can the following

c_type_tag (type) == NULL_TREE && DECL_NAME (field) == NULL_TREE

Be the condition? 


> 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.

Thanks for the info, will take a look at the logical there.

>  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.

Okay, thanks.

Qing
> 
> -- 
> Joseph S. Myers
> [email protected]
> 

Reply via email to