Placement of variable declarations in C
Posted Oct 26, 2007 16:47 UTC (Fri) by
giraffedata (subscriber, #1954)
In reply to:
Placement of variable declarations in C by RobSeace
Parent article:
A potential competitor for GCC: pcc
Sometimes, one uses the same variable in multiple blocks within a single function...
Then the scope in which it is used is the block that contains those blocks. Unless you're talking about reusing a C variable for multiple values, which is something else I don't tolerate.
And I don't use the index variable of a for structure outside of the structure,
You don't? I often do... Sometimes, when you break out of the loop, you need to know the
value of the index at that point for some reason or other (null terminate a string, obtain an
array count, etc.)...
I'm a structured programmer, so I never break out of a loop. In fact, I don't even recognize a for structure as a "loop." Structured programs don't branch.
Or, I could just be a grumpy old C coder, too set in his ways, too... ;-)
You sound like a very typical C coder; I'm unusual. C coders tend to be low-level coders; they write code which is a set of instructions to a computer. A variable is a storage location. Declarations get in your way. But I use C only grudgingly, in a careful paradigm to make it look like a high level language. High level code is a description of the solution to a computational problem. Its audience is a person, not a computer, and a compiler's job is create a low-level program that implements it. A variable is a symbol for a piece of information and the declarations are the heart of the code (indeed where most of my comments are).
(
Log in to post comments)