What do you think of these coding strategies?

Ron Hudson ron.hudson@sbcglobal.net
Mon Feb 28 18:14:00 GMT 2005


I have some philosophical questions for the Wise Ones of C programming.


To limit the scope of index variables, I saw this the other day
but it might be C++ or something (perhaps even c#)

for(int x=1; x < 10; x++) {
	/* x is good here */
	printf("%d \n",x);
}

/* x no longer good */


How about:

if (x == 3) {
	int j;    /* explain local j*/
	int k;    /* explain local k*/

     j = 3;
  	k = something;

}

To "hide j and k, only used inside the if statement, and to define them 
nearer to
where they are used.

------------

I have been told that global variables are bad... I am writing my own 
star-trek program and
I use two big arrays to hold the Quadrant and Sector grids, I make 
these global variables
so I don't have to pass them around.  Bad?

-------------

When I finish my Star-Trek game, is there a place I can post it for 
critique?



More information about the Gcc-help mailing list