Skip to content

Make array size match array literal size #851

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

Merged
merged 1 commit into from
Oct 20, 2021
Merged

Conversation

briandk
Copy link
Contributor

@briandk briandk commented Oct 20, 2021

The problem

Currently, one of the sample lines of code in the array documentation declares an array of size 6, but assigns it a value of an array literal whose length is 5:

// the length of the literal is 5, but the declared length is 6
int mySensVals[6] = {2, 4, -8, 3, 2}; 

This discrepancy has been confusing to me and my students, and may also result in undefined compiler behavior. (I'm not an expert on the Arduino-C compiler, but depending on how it resolves this statement it may result in an array of size 6 whose last element is garbage and/or whatever happened to be at that memory address.)

My suggestion

Make the declaration be for an array of size 5 (instead of size 6). This solution keeps much of the documentation the same, changing only the declared array size.

@CLAassistant
Copy link

CLAassistant commented Oct 20, 2021

CLA assistant check
All committers have signed the CLA.

Copy link
Collaborator

@per1234 per1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much @briandk!

@per1234 per1234 merged commit 86383e1 into arduino:master Oct 20, 2021
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

Successfully merging this pull request may close these issues.

3 participants