P
partremmaps
Of course I could use malloc and all that but this isn't about that.
Often I do like the following:
int i
#define sizeMAX 1024
static char buffer[sizeMAX];
i=0;
while(i<sizeMAX)
{
putc(buffer);
}
.... lots more code that reference buffer[] and sizeMAX ...
#undef sizeMAX
But this seems messy because I could forget the #undef and then that #define is left active for anything following in the code.
I tried const int sizeMAX=1024 but of course the declaration of buffer doesn't allow that as an array size specifier.
However, doing "enum { sizeMAX=1024 };" seems to work, but I can't tell from a quick word search in the standard whether it is supposed to always work.
Obviously enum was meant to map multiple words to a list of ints, and if the standard allows that list to be set up at run time then it may not work in some standard implementations.
Logically, "const int x=5" would be of the same functionality as "enum {x=5}" however GCC treats them differently, allowing the enum'ed x to be used as the array size specifier while not allowing the const int to be used as such.
Thanks,
Jesse
Often I do like the following:
int i
#define sizeMAX 1024
static char buffer[sizeMAX];
i=0;
while(i<sizeMAX)
{
putc(buffer);
}
.... lots more code that reference buffer[] and sizeMAX ...
#undef sizeMAX
But this seems messy because I could forget the #undef and then that #define is left active for anything following in the code.
I tried const int sizeMAX=1024 but of course the declaration of buffer doesn't allow that as an array size specifier.
However, doing "enum { sizeMAX=1024 };" seems to work, but I can't tell from a quick word search in the standard whether it is supposed to always work.
Obviously enum was meant to map multiple words to a list of ints, and if the standard allows that list to be set up at run time then it may not work in some standard implementations.
Logically, "const int x=5" would be of the same functionality as "enum {x=5}" however GCC treats them differently, allowing the enum'ed x to be used as the array size specifier while not allowing the const int to be used as such.
Thanks,
Jesse