Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: How to fix the [-Wreorder] warnings?

  1. #1

    How to fix the [-Wreorder] warnings?

    I use the following library for my encoders: https://github.com/sixeight7/encoder

    Everytime I compile it, it generates the following warnings:

    Code:
    In file included from /Users/cfeddema/Documents/Arduino/libraries/encoder-arduino/ClickEncoder.cpp:12:0:
    /Users/cfeddema/Documents/Arduino/libraries/encoder-arduino/ClickEncoder.h: In constructor 'ClickEncoder::ClickEncoder(uint8_t, uint8_t, uint8_t, uint8_t, bool)':
    /Users/cfeddema/Documents/Arduino/libraries/encoder-arduino/ClickEncoder.h:112:8: warning: 'ClickEncoder::accelerationEnabled' will be initialized after [-Wreorder]
       bool accelerationEnabled;
    
            ^
    /Users/cfeddema/Documents/Arduino/libraries/encoder-arduino/ClickEncoder.h:103:20: warning:   'volatile int16_t ClickEncoder::delta' [-Wreorder]
       volatile int16_t delta;
    
                        ^
    /Users/cfeddema/Documents/Arduino/libraries/encoder-arduino/ClickEncoder.cpp:46:1: warning:   when initialized here [-Wreorder]
     ClickEncoder::ClickEncoder(uint8_t A, uint8_t B, uint8_t BTN, uint8_t stepsPerNotch, bool active)
     ^
    In file included from /Users/cfeddema/Documents/Arduino/libraries/encoder-arduino/ClickEncoder.cpp:12:0:
    /Users/cfeddema/Documents/Arduino/libraries/encoder-arduino/ClickEncoder.h:110:19: warning: 'ClickEncoder::button' will be initialized after [-Wreorder]
       volatile Button button;
    
                       ^
    /Users/cfeddema/Documents/Arduino/libraries/encoder-arduino/ClickEncoder.h:101:11: warning:   'uint8_t ClickEncoder::steps' [-Wreorder]
       uint8_t steps;
    
               ^
    /Users/cfeddema/Documents/Arduino/libraries/encoder-arduino/ClickEncoder.cpp:46:1: warning:   when initialized here [-Wreorder]
     ClickEncoder::ClickEncoder(uint8_t A, uint8_t B, uint8_t BTN, uint8_t stepsPerNotch, bool active)
     ^
    In file included from /Users/cfeddema/Documents/Arduino/libraries/encoder-arduino/ClickEncoder.cpp:12:0:
    /Users/cfeddema/Documents/Arduino/libraries/encoder-arduino/ClickEncoder.h:101:11: warning: 'ClickEncoder::steps' will be initialized after [-Wreorder]
       uint8_t steps;
    
               ^
    /Users/cfeddema/Documents/Arduino/libraries/encoder-arduino/ClickEncoder.h:98:17: warning:   'const uint8_t ClickEncoder::pinA' [-Wreorder]
       const uint8_t pinA;
    
                     ^
    /Users/cfeddema/Documents/Arduino/libraries/encoder-arduino/ClickEncoder.cpp:46:1: warning:   when initialized here [-Wreorder]
     ClickEncoder::ClickEncoder(uint8_t A, uint8_t B, uint8_t BTN, uint8_t stepsPerNotch, bool active)
     ^
    De schets gebruikt 244828 bytes (23%)  programma-opslagruimte. Maximum is 1048576 bytes.
    Globale variabelen gebruiken 99152 bytes (37%) van het dynamisch geheugen. Resteren 162992 bytes voor lokale variabelen. Maximum is 262144 bytes.
    How could I fix these warnings?

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    7,619
    Hopefully one of the more compiler oriented members can give a more complete answer. But usually when I see things like this, it is because the order of the initializers is not the same order of the definitions in the class:

    That is the constructor looks like:
    Code:
    ClickEncoder::ClickEncoder(uint8_t A, uint8_t B, uint8_t BTN, uint8_t stepsPerNotch, bool active)
      : doubleClickEnabled(true), accelerationEnabled(true),
        delta(0), last(0), acceleration(0),
        button(Open), steps(stepsPerNotch),
        pinA(A), pinB(B), pinBTN(BTN), pinsActive(active)
    {
    ...
    So the question is are all of the member variables in the same order?

    And I don't remember how having some of the variables in the class when have initial values and some do not, impacts the expected order of these initializers.

  3. #3
    Thanks Kurt. I changed the order in the constructor to the order that was shown in encoder.h and now it compiles without warnings.

    Here is the new constructor:
    Code:
    ClickEncoder::ClickEncoder(uint8_t A, uint8_t B, uint8_t BTN, uint8_t stepsPerNotch, bool active)
      : pinA(A), pinB(B), pinBTN(BTN), steps(stepsPerNotch),
        pinsActive(active), delta(0), last(0), acceleration(0),
        button(Open), doubleClickEnabled(true), accelerationEnabled(true)
    And here is where I found the correct order in encoder.h:
    Code:
    private:
      const uint8_t pinA;
      const uint8_t pinB;
      const uint8_t pinBTN;
      uint8_t steps;
      const bool pinsActive;
      volatile int16_t delta;
      volatile int16_t last;
      volatile uint16_t acceleration;
    #if ENC_DECODER != ENC_NORMAL
      static const int8_t table[16];
    #endif
    #ifndef WITHOUT_BUTTON
      volatile Button button;
      bool doubleClickEnabled;
      bool accelerationEnabled;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •