Apr 23, 2010 at 12:21 PM: Thomas Giesel <skoe@directbox.com> wrote: > On many compilers it gives better results to declare all variables > at the beginning and not in nested blocks. This is because the > stack frame is extended and shrinked on block entries and exits. I would consider that primarily a compiler limitation. In my compiler work I've always mapped the stack space for the whole function at once. I can't think of any advantage to the extra stack work; in fact before now, that option never even crossed my mind. > In C the reasons to do this are rare. In C++ it may be useful if > constructors are involved, but that's a completely different language, I assume you are referring to declaring variables in the body of the text? I come from a Pascal background (after C64 BASIC and ML, of course) so when I took up C/C++ this was a foreign concept. However, I've grown to like the flexibility--I'd rather see a declaration near where the variable is first used. I don't declare all variables this way; I think the primary vars are best at the top of the function. But for variabls that are not clearly part of the function's overall purpose, I think that to put them at the top just makes extra clutter there that deter from the more important identifiers. [I am NOT trying to fight a holy war here... just sharing a perspective.] // Steve ---------------------------------------------------------------------- To unsubscribe from the list send mail to majordomo@musoftware.de with the string "unsubscribe cc65" in the body(!) of the mail.Received on Sat Apr 24 09:23:01 2010
This archive was generated by hypermail 2.1.8 : 2010-04-24 09:23:04 CEST