|
|
Subscribe / Log in / New account

Placement of variable declarations in C

Placement of variable declarations in C

Posted Oct 27, 2007 15:58 UTC (Sat) by tjc (guest, #137)
In reply to: Placement of variable declarations in C by RobSeace
Parent article: A potential competitor for GCC: pcc

Just declare one "int i;" at the top of the function, and use it in ALL for() loops! ;-)
If you're not too set in your ways you might want to try "int ii;" instead. I've been doing this for a few years, and while it looks odd at first, I got used to it. It's a lot easier to find "ii" in code; searching for "i" is futile.


to post comments

(off-topic) Searching for variables

Posted Nov 18, 2008 18:40 UTC (Tue) by pjm (guest, #2080) [Link]

You would benefit a lot from learning regular expressions. If you use vim, then it suffices to type ‘*’ when the cursor is over an ‘i’ variable to find all occurrences of ‘i’ as a “word” (so excluding ‘if’ etc.).

Many IDEs go one step farther and allow searching for just the current variable as distinct from other variables & functions of the same name.

Incidentally, I hope that the original poster is joking (as the ‘;-)’ suggests) in the suggestion to use a shared variable for all temporaries. Such sharing makes it harder to modify one use of the variable because one needs to check whether subsequent code is using the resulting value.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds