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

Update JC_Button.h #14

Closed
wants to merge 1 commit into from
Closed

Update JC_Button.h #14

wants to merge 1 commit into from

Conversation

tysonlt
Copy link

@tysonlt tysonlt commented May 13, 2018

Hello JC!

Thank you for this wonderful library. I found it after struggling with another library, and this does exactly what I need.

I had to make the following changes to prevent compiler warnings. No actual functionality has been changed.

Simple changes to prevent gcc compiler warnings
@JChristensen
Copy link
Owner

Hello @tysonlt! Thanks for the note, glad you like the library.
Oddly, I do not see any compiler warnings with Arduino 1.8.5. Are you using something different? What exactly are the warning messages?

@JChristensen
Copy link
Owner

Had a closer look at this. Yes the scope doesn't belong on line 23 of the .h file so I will make that change. It is odd that I don't see any compiler warnings.

But I do not understand the other change, just moving the definition of m_time up a few lines. Surely that cannot make a difference. Am I missing something?

@tysonlt
Copy link
Author

tysonlt commented May 14, 2018 via email

@JChristensen
Copy link
Owner

My bad -- now that I have warnings turned up a bit, I see the same messages too!
Indeed order does make a difference. I was unaware of that. Thanks for the catch, I learned something here!

learncpp.com is a site I like. Initializer order is mentioned on this page:

Initializer list order

Perhaps surprisingly, variables in the initializer list are not initialized in the order that they are specified in the initializer list. Instead, they are initialized in the order in which they are declared in the class.

For best results, the following recommendations should be observed:

  1. Don’t initialize member variables in such a way that they are dependent upon other member variables being initialized first (in other words, ensure your member variables will properly initialize even if the initialization ordering is different).
  2. Initialize variables in the initializer list in the same order in which they are declared in your class. This isn’t strictly required so long as the prior recommendation has been followed, but your compiler may give you a warning if you don’t do so and you have all warnings turned on.

@JChristensen
Copy link
Owner

PS: In the pull request, the m_time variable is moved but it should have been m_dbTime.

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.

None yet

2 participants