C1x の匿名構造について少し混乱しています。適切に変換された構造体ポインターがその最初のメンバーを指すという規則は、最初の匿名構造体に適用されますか、それとも単に最初の匿名構造体の最初のメンバーに適用されますか? 特に、このプログラムは C1x で意味がありますか?
#include<stdio.h>
struct node {
struct node *next;
};
/* Does C1x even allow this? Do I have to define struct node inside of inode?
* Are anonymous struct members even allowed to have tags?
*/
struct inode {
struct node;
int data;
};
int main(void) {
inode node1 = {NULL, 12};
inode *ihead = &inode;
node *head = (struct node *)ihead;
/* These should work since struct inode's first member is a struct node. */
printf("Are these equal? %c", head == &node1.next ? 'Y' : 'N');
printf("Is next NULL? %c", head->next == NULL ? 'Y' : 'N');
return 0;
}
この回答は、匿名の構造体ではなく、名前のない構造体について質問している可能性があることを示唆しています。匿名構造体の性質を完全に誤解していますか?