Skip to content

Initialization of variables in c/c++ #360

Open
@hellooutthere2

Description

@hellooutthere2

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions