E
elzacho
I would like to (and commonly do) define my variables in the most
specific scope I can. For example...
int foo(int a, int b, int c)
{
/* don't declare temp here if we can help it */
...
for (i = 0; i < max; i++)
{
/* declare here */
int temp;
...
/* use temp */
}
}
But my concern is, does the declaration take up cpu time? One can
imagine that temp could be a huge array or max could be a large number.
In this case, if the declaration maps to any cpu time when compiled,
this could lead to a significant performance drop.
So, is there a difference in the machine code between declaring all of
your variables at outer most scope or inner most scope? My impressions
on C are that it makes does not impose how this is handled, rather that
this is a compiler issue, but I am not sure how much the standards
dictate this. Thought I would pass it by some experts.
Zach
specific scope I can. For example...
int foo(int a, int b, int c)
{
/* don't declare temp here if we can help it */
...
for (i = 0; i < max; i++)
{
/* declare here */
int temp;
...
/* use temp */
}
}
But my concern is, does the declaration take up cpu time? One can
imagine that temp could be a huge array or max could be a large number.
In this case, if the declaration maps to any cpu time when compiled,
this could lead to a significant performance drop.
So, is there a difference in the machine code between declaring all of
your variables at outer most scope or inner most scope? My impressions
on C are that it makes does not impose how this is handled, rather that
this is a compiler issue, but I am not sure how much the standards
dictate this. Thought I would pass it by some experts.
Zach