Local structure in c

If a structure is used in only one function, can I declare it in this function? Can i do this:

int func() { struct { int a, b; } s; sa=5; return sa; } 

gcc gasped, but it made a very strange looking mistake that I couldn’t understand, instead of saying "Sorry, you cannot do this."

+6
source share
1 answer

This is a valid C89 / C99 / C11 code, this is a tagless structure, and the object has a block scope. Check C99 6.7.2.3p6 to see the tag identifier is optional.

+9
source

Source: https://habr.com/ru/post/917978/


All Articles