From: Cameron S. <cs...@zi...> - 2003-02-01 23:22:57
|
On 20:13 30 Jan 2003, Bastien Nocera <ha...@ha...> wrote: | +#define NUM_RESOLUTIONS 5 | +static struct { | + int width; | + int height; | +} resolutions[NUM_RESOLUTIONS] = { | + { 768, 576 }, | + { 640, 480 }, | + { 384, 288 }, | + { 320, 240 }, | + { 160, 120 }, | +}; Consider changing: } resolutions[NUM_RESOLUTIONS] = { into } resolutions[] = { and #define NUM_RESOLUTIONS 5 into #define NUM_RESOLUTIONS (sizeof(resolutions)/sizeof(resolutions[0])) so it tracks the array size automatically. I have a macro somewhere [... aha ...] I use routinely for this kind of thing: /* number of elements in an array */ #define nsizeof(array) (sizeof(array)/sizeof((array)[0])) so #define NUM_RESOLUTIONS nsizeof(resolutions) if you care to use it. One fewer magic numbers in the code. Cheers, -- Cameron Simpson, DoD#743 cs...@zi... http://www.zip.com.au/~cs/ When you are in it up to your ears, keep your mouth shut. |