In my application I just need a simple fixed length array, but want to use some sort of a label value rather than a hard number (like 128) because that array size value will be used in a couple of places in my code, primarily to range check the array index (I've been burned enough by my own code that I like a belt-and-suspenders approach to keeping array indices in bounds).Īnd I wasn't aware that I was using a C compiler as opposed to a C++ compiler when using the MPLAB X IDE. I'm at such a nube level that I didn't even know that a VLA was a thing, or even possible. Is there some better way to define the size of the array than using a #define? Or should I just stick with #define?Īlso, why did the const work with Arduino but not the MPLAX X IDE with GCC compiler? Is this again related to the flash or RAM size of the target?ĪndreyT wrote: would you be happy with a VLA or do you definitely need a "classic" non-VLA array? To move forward, I can go with the #define, but I always thought that const was preferred to #define, since #define is a text substitution. When I change the declaration of BUFMAX to one using a #define as in: Newmain.c:7:9: error: variably modified 'testArray' at file scope When I try defining my array size using a uint8_t constant and compile via MPLAB X IDE I get an error regarding the declaration of the array. I'm now starting to work with MPLAB X IDE and the GCC compiler with an AVR128DB48 target (I'm moving away from XC8 after my address space problems). Was acceptable, no error messages when compiling. Most of my AVR programming has been on Arduino where doing something like: