The compiler sends me a folding constant warning about the following code snippet:
Code:
The file name is gui.h. It provides function definitions and constants for implementation file, gui.c. The precise wording of the compiler error is:
Code:
I need the TEXT_BUTTON_MAX_TEXT_LEN to be a constant since I use it in the implementation file. The "plus 1" in the array declaration tacks on room for the null terminator.
I didn't find anything about how to fix this warning on DuckDuckGo. What should I do to fix/silence this warning?
Code:
// Text button constants
// =========================
const uint8_t TEXT_BUTTON_HEIGHT = 25;
const uint8_t TEXT_BUTTON_MAX_TEXT_LEN = 30;
// This pads text and toggle switches within buttons.
const uint8_t TEXT_BUTTON_CONTENT_PADDING = 10;
const uint8_t TEXT_BUTTON_LEFT_MARGIN_TEXT = 1;
const uint8_t TEXT_BUTTON_CENTER_TEXT = 2;
// ==========================
typedef struct
{
char text[TEXT_BUTTON_MAX_TEXT_LEN + 1]; // This is the problem line
// This should be one of the following:
// TEXT_BUTTON_LEFT_MARGIN_TEXT, TEXT_BUTTON_CENTER_TEXT
uint8_t text_horiz_pos;
uint8_t text_color;
uint8_t button_color;
uint24_t button_width;
} text_button_t;
The file name is gui.h. It provides function definitions and constants for implementation file, gui.c. The precise wording of the compiler error is:
Code:
src/gui.h:43:14: warning: variable length array folded to constant array as an extension [-Wgnu-folding-constant]
char text[TEXT_BUTTON_MAX_TEXT_LEN + 1];
I need the TEXT_BUTTON_MAX_TEXT_LEN to be a constant since I use it in the implementation file. The "plus 1" in the array declaration tacks on room for the null terminator.
I didn't find anything about how to fix this warning on DuckDuckGo. What should I do to fix/silence this warning?