What do you think of these coding strategies?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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?


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux