When creating a variable used within a loop, is it quicker/more effecient to redefine the variable every loop repetition or define it once in a higher scope? I.E.:vs.Code:while(p != NULL)
{
char buf[BUFSIZ];
strcpy(buf, p->str);
}
So in the former, buf is being redefined every iteration, which may maximize the use of space, but in the latter, time is not wasted setting up space again and again (however, buf must still at least be passed on the stack, right?). So I'm wondering if there really is a space/speed tradeoff between the two? Which is faster? more effecient? Or does it even really matter if you have an optimizing compiler (i.e. gcc (-O3))?Code:char buf[BUFSIZ];
while(p != NULL)
{
strcpy(buf, p->str);
}