dscKeybusInterface icon indicating copy to clipboard operation
dscKeybusInterface copied to clipboard

Initialization of variables in c/c++

Open hellooutthere2 opened this issue 1 year ago • 0 comments

I haven't programmed in awhile but I don't think much has changed.

Need to add initializers to new objects: dscKeybusInterface.cpp line 317,318 previousTime and setPartition are used without being initialized.

Example:

void dscKeybusInterface::setWriteKey(const char receivedKey) { static unsigned long previousTime; static bool setPartition;

// Sets the write partition if set by virtual keypad key '/' if (setPartition) {....

Basis: In C++, a bool variable that is not explicitly initialized will have an indeterminate value. This means it could be either true or false, depending on whatever value happens to be in the memory location assigned to the variable. To ensure predictable behavior, you should always initialize your bool variables

Pretty sure this holds true for all objects.

hellooutthere2 avatar Oct 29 '24 12:10 hellooutthere2