Re: Identifying variables: what process do you follow?
On Oct 16, 9:23 am, Kevin Walzer <k...@codebykevin.com> wrote:
> With C, such an approach doesn't seem practical. You need to identify
> some variables ahead of time just to have a program that will compile!
C99 (which is the latest standard) allows mixed declarations and code,
but is not widely implemented in full; however, in C90, you can also
do something like the following:
int myfunction (void) {
int a = 5;
/* do stuff with 'a' here */
{
int b = 6;
/* do stuff with 'a' and 'b' here */
}
/* do more stuff with 'a' here */
return a;
}
The scope of the variable 'b' begins at the inner opening brace and
ends at the inner closing brace, and as long as you keep its
declaration at the very beginning of that scope, it's legal in both
C90 and C99. Any amount of nested braces is allowed as well.
|