Dubious use of static (internal linkage) in firmware header files


The use of static for variable declarations in header files in the firmware doesn’t seem like a good idea. These should be moved to the cpp.

The header files in the firmware often define variables with static (internal) linkage. This results in distinct memory and references being allocated in every .cpp that includes the header file. (they don’t even point to the same memory, so you can’t even use it really). This is a waste of space

So for example the firmware ino file includes BrickPiUART.h, which declares a buffer for reading in messages:

static uint8_t UART_FULL_ARRAY[128];

based on this the compiler will create a statically linked (file local) version of that 128 buffer in both the ino module and the BrickPiUART.o module (and in fact every module that includes the header file.)

While the code works (because no other modules refer to those variables), I don’t see why you would do this. Instead all of those statics should be moved to the .cpp files… saving a lot of space in the image (and also preserving some level of encapsulation).


Hey chahld, thanks so much for the advice. The next time we crack open the firmware, we’ll try to make these changes. Thanks again.



Added to Github stack.