The compilation effects of declaring all locales of visibility at the beginning, like at the beginning of C?

I remember hearing that aligning all the elements of a sphere at the beginning of a block is no longer recommended to practice with both C and C ++, but does this mean that it prevents the compiler from somehow generating code or is it just not longer need to do because it is not always convenient? AKA is it more efficient for the compiler to generate an optimal distribution if local residents are declared upon request?

+4
source share
1 answer

It used to be mandatory to declare local residents in C, presumably because it is easier to implement a compiler when that is.

Nowadays, the compiler is actually "quite advanced", which does not matter for POD types. Because of this, the question boils down to readability and taste issues in C.


In C ++, however, declaring locals implies things about executing the appropriate constructor and destructor, and this may have to do with whether the compiler can use certain optimizations. This means that declaring them all at the top is not equivalent to declaring them on demand, which makes your question mostly invalid for C ++.

In C ++, declare variables when they are semantically correct for the program you are trying to write. (And besides, there are also issues of readability and taste)

+5

All Articles