Structure within the union showing a warning and some unpredictable result

#include<stdio.h> typedef union { struct accname { char sbi[20]; char canara[20]; char hdfc[20]; char icici[20]; }; } unionv; void main() { unionv var1; struct accname var2; printf("sizeof union=%d\n",sizeof(var1)); printf("sizeof str=%d\n",sizeof(var2)); } 

A warning is displayed here.

 warning: declaration does not declare anything [enabled by default] }unionv 

Can anyone understand why he is warning?

+5
source share
1 answer

According to https://gcc.gnu.org/onlinedocs/gcc/Unnamed-Fields.html#Unnamed-Fields

An unnamed field should be a structure or union definition without a tag, e.g.

 typedef union { struct accname { //member }; // without tag } unionv; 

If -fms-extensions , the field can also be a tag definition, for example struct foo { int a; }; struct foo { int a; }; , a reference to a previously defined structure or union , for example struct foo or a reference to the typedef name for a previously defined type of structure or union .

0
source

All Articles