>> Yes, this is what I normally do (and of course I would use a #define
inside foo anyway) but the problem is that I might change my mind about
the size of foo->x and then I have to search for all occurrences of the
#define. With this new style I can see that my intent was to force one
array to be the same as another one. With the #define the link between
the two arrays is not clear in isolation.
All occurrences of the #define? I surely hope you would only #define it
once!
If you have multiple files, put the #define in an include file that is
included in all of the source files.
Right, #define once, in one header file.
If the macro name is chosen meaningfully, it is perfectly clear about the
size and what it means: the same size as anything declared using XCOUNT.
Or name it FOO_XCOUNT if you want to point out that 'foo' is the
primary driver.
That goes a long way toward keeping things organized. However, if I go back
to a set of source files I haven't worked on in a long time I might decide
that foo->x really needs to be a different size, perhaps based on a
different #define (e.g. maybe it should be exactly MAX_PATH+1 or something
like that.) I could now #define FOO_XCOUNT to be MAX_PATH+1 but I'd really
like to see the meaningful MAX_PATH+1 in the array declaration so at that
point I have to grep through my sources to find out who else is using
FOO_XCOUNT. With this new construct I'm using it's automatic.
Andrew