Here is a snippet of the code I have:
class modbus {
public:
static const uint8_t modbusHeader = 2;
static const uint8_t modbusCRC = 2;
static const uint8_t modbusPDU = modbusHeader + modbusCRC;
static const uint8_t exceptionBase = 0x80;
static const uint32_t transmitTimeout = 5000;
};
It defines some sizes for the modbus packets that I need to create inside the class. I work inside an embedded environment and as such size optimisations and considerations are always there. As such I really want to have only one occurrence of these constant values inside my read only part of the flash.
I have chosen to set these variables as static
but is this necessary? Would a compiler infer that these values need only be saved once inside the binary and as such only include them once when I remove the static
keyword?