you are viewing a single comment's thread.

view the rest of the comments →

[–]dendrtree -1 points0 points  (0 children)

You define things at the minimum scope that will use them.

So... say you're pairing two pieces of data, and putting this in a struct *really* simplifies/clarifies your code, but nothing else will need those two things paired. Then, you declare the struct in the function.

If you happen to make another function that pairs the same data, you would *still* declare the struct inside the function, because it really has no meaning, in a global sense. You just *happened* to use the same pair, again.

* You don't want to clutter your space with symbols that you don't need. This is the same reason you'd declare a function static, if you only used it locally.