Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialization of variables in c/c++ #360

Open
hellooutthere2 opened this issue Oct 29, 2024 · 0 comments
Open

Initialization of variables in c/c++ #360

hellooutthere2 opened this issue Oct 29, 2024 · 0 comments

Comments

@hellooutthere2
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant