I'm a bit confused about anonymous structures in C1x. Does the rule that a struct pointer, suitably converted, points to it's first member apply to an initial anonymous struct, or simply to the initial member of an initial anonymous struct? In particular, does this program make sense in 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;
}
This answer suggests that I may be asking about unnamed structs instead of anonymous structs. Am I completely misunderstanding the nature of anonymous structs?