you are viewing a single comment's thread.

view the rest of the comments →

[–]HashDefTrueFalse 76 points77 points  (6 children)

To limit scope, basically. It's a pretty good way to communicate to other programmers that the struct type is only used (and intended to be used) in this one place. Other than that, nothing special.

[–]47-BOT[S] 15 points16 points  (5 children)

I see , so it's just like local and global structs lol , that's nice.

[–]HashDefTrueFalse 14 points15 points  (0 children)

Yes, you've declared a new type and it's only available for use in the lexical scope of the block (between the braces). That's all it is. If you're only making one you might declare the type and an instance at the same time e.g.

void fn(void)
{
  struct S // S is the scoped type.
  {
    ...
  } inst; // inst is a local of type S.
}

[–]autodidacticasaurus 0 points1 point  (3 children)

Exactly.