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

Thread: -Wextra

  1. #1
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679

    -Wextra

    -Wextra emits a bunch of warnings when compiling the core-files.
    I've wrote a pull-request yesterday, which fixes some of them, but there are many left.
    There are two types of warnings :
    a) warning: unused parameter [-Wunused-parameter]
    and
    b) warning: comparison between signed and unsigned integer expressions [-Wsign-compare]

    While b) really needs an individual fix per warning, a) is not as important (low priority).

    A suggestion for "warning: unused parameter" is to use a macro like this:
    Code:
    #define UNUSED(x) (void)(x)
    - or to use the attribute in the macro:
    Code:
    #ifdef __GNUC__
    #  define UNUSED(x) UNUSED_ ## x __attribute__((__unused__))
    #else
    #  define UNUSED(x) UNUSED_ ## x
    #endif
    
    #ifdef __GNUC__
    #  define UNUSED_FUNCTION(x) __attribute__((__unused__)) UNUSED_ ## x
    #else
    #  define UNUSED_FUNCTION(x) UNUSED_ ## x
    #endif
    (taken from https://stackoverflow.com/questions/...ings-in-c-code)



    some examples:
    Code:
    C:\Arduino\hardware\teensy\avr\libraries\Audio/analyze_fft256.h:89:31: warning: unused parameter 'n' [-Wunused-parameter]
    
      void averageTogether(uint8_t n) {
    
                                   ^
    
    In file included from C:\Arduino\hardware\teensy\avr\libraries\Audio/Audio.h:62:0,
    
                     from C:\Users\Frank\Documents\Arduino\libraries\Teensy64_new/Teensy64.h:8,
    
                     from C:\Users\Frank\Documents\Arduino\c64\c64.ino:3:
    
    C:\Arduino\hardware\teensy\avr\libraries\Audio/analyze_fft1024.h:81:31: warning: unused parameter 'n' [-Wunused-parameter]
    
      void averageTogether(uint8_t n) {
    
                                   ^
    
    In file included from C:\Arduino\hardware\teensy\avr\libraries\Audio/Audio.h:68:0,
    
                     from C:\Users\Frank\Documents\Arduino\libraries\Teensy64_new/Teensy64.h:8,
    
                     from C:\Users\Frank\Documents\Arduino\c64\c64.ino:3:
    
    C:\Arduino\hardware\teensy\avr\libraries\Audio/control_sgtl5000.h:40:24: warning: unused parameter 'n' [-Wunused-parameter]
    
      bool inputLevel(float n) {return false;}
    
                            ^
    
    In file included from C:\Arduino\hardware\teensy\avr\libraries\Audio/Audio.h:69:0,
    
                     from C:\Users\Frank\Documents\Arduino\libraries\Teensy64_new/Teensy64.h:8,
    
                     from C:\Users\Frank\Documents\Arduino\c64\c64.ino:3:
    
    C:\Arduino\hardware\teensy\avr\libraries\Audio/control_wm8731.h:39:23: warning: unused parameter 'n' [-Wunused-parameter]
    
      bool inputSelect(int n) { return false; }
    
                           ^
    
    In file included from C:\Arduino\hardware\teensy\avr\libraries\Audio/Audio.h:70:0,
    
                     from C:\Users\Frank\Documents\Arduino\libraries\Teensy64_new/Teensy64.h:8,
    
                     from C:\Users\Frank\Documents\Arduino\c64\c64.ino:3:
    
    C:\Arduino\hardware\teensy\avr\libraries\Audio/control_ak4558.h:245:24: warning: unused parameter 'n' [-Wunused-parameter]
    
      bool inputLevel(float n) { return false; } //not supported by AK4558
    
                            ^
    
    C:\Arduino\hardware\teensy\avr\libraries\Audio/control_ak4558.h:246:23: warning: unused parameter 'n' [-Wunused-parameter]
    
      bool inputSelect(int n) { return false; } //sets inputs to mono left, mono right, stereo (default stereo), not yet implemented
    
                           ^
    
    In file included from C:\Arduino\hardware\teensy\avr\libraries\Audio/Audio.h:71:0,
    
                     from C:\Users\Frank\Documents\Arduino\libraries\Teensy64_new/Teensy64.h:8,
    
                     from C:\Users\Frank\Documents\Arduino\c64\c64.ino:3:
    
    C:\Arduino\hardware\teensy\avr\libraries\Audio/control_cs4272.h:41:24: warning: unused parameter 'n' [-Wunused-parameter]
    
      bool inputLevel(float n) { return false; }
    
                            ^
    
    C:\Arduino\hardware\teensy\avr\libraries\Audio/control_cs4272.h:42:23: warning: unused parameter 'n' [-Wunused-parameter]
    
      bool inputSelect(int n) { return false; }
    
                           ^
    
    In file included from C:\Arduino\hardware\teensy\avr\libraries\Audio/Audio.h:89:0,
    
                     from C:\Users\Frank\Documents\Arduino\libraries\Teensy64_new/Teensy64.h:8,
    
                     from C:\Users\Frank\Documents\Arduino\c64\c64.ino:3:
    
    C:\Arduino\hardware\teensy\avr\libraries\Audio/input_i2s.h:41:20: warning: unused parameter 'dummy' [-Wunused-parameter]
    
      AudioInputI2S(int dummy): AudioStream(0, NULL) {} // to be used only inside AudioInputI2Sslave !!
    
                        ^
    
    In file included from C:\Arduino\hardware\teensy\avr\libraries\Audio/Audio.h:95:0,
    
                     from C:\Users\Frank\Documents\Arduino\libraries\Teensy64_new/Teensy64.h:8,
    
                     from C:\Users\Frank\Documents\Arduino\c64\c64.ino:3:
    
    C:\Arduino\hardware\teensy\avr\libraries\Audio/output_i2s.h:42:21: warning: unused parameter 'dummy' [-Wunused-parameter]
    
      AudioOutputI2S(int dummy): AudioStream(2, inputQueueArray) {} // to be used only inside AudioOutputI2Sslave !!
    
                         ^
    
    In file included from C:\Arduino\hardware\teensy\avr\libraries\Audio/Audio.h:98:0,
    
                     from C:\Users\Frank\Documents\Arduino\libraries\Teensy64_new/Teensy64.h:8,
    
                     from C:\Users\Frank\Documents\Arduino\c64\c64.ino:3:
    
    C:\Arduino\hardware\teensy\avr\libraries\Audio/output_spdif.h:40:23: warning: unused parameter 'dummy' [-Wunused-parameter]
    
      AudioOutputSPDIF(int dummy): AudioStream(2, inputQueueArray) {}
    
                           ^
    
    In file included from C:\Arduino\hardware\teensy\avr\libraries\Audio/Audio.h:109:0,
    
                     from C:\Users\Frank\Documents\Arduino\libraries\Teensy64_new/Teensy64.h:8,
    
                     from C:\Users\Frank\Documents\Arduino\c64\c64.ino:3:
    
    C:\Arduino\hardware\teensy\avr\libraries\Audio/synth_waveform.h:113:53: warning: unused parameter 'maxFreq' [-Wunused-parameter]
    
       void arbitraryWaveform(const int16_t *data, float maxFreq) {
    
                                                         ^
    
    In file included from C:\Arduino\hardware\teensy\avr\libraries\Audio/Audio.h:113:0,
    
                     from C:\Users\Frank\Documents\Arduino\libraries\Teensy64_new/Teensy64.h:8,
    
                     from C:\Users\Frank\Documents\Arduino\c64\c64.ino:3:
    
    C:\Arduino\hardware\teensy\avr\libraries\Audio/synth_karplusstrong.h:53:21:  warning: unused parameter 'velocity' [-Wunused-parameter]
    
      void noteOff(float velocity) {
    I'd suggest to fix b) for the next release of teensyduino .
    some examples:
    Code:
    "C:\Arduino\hardware\teensy/../tools/arm/bin/arm-none-eabi-gcc" -c -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD  -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -D__MK66FX1M0__ -DTEENSYDUINO=137 -DARDUINO=10803 -DF_CPU=240000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "@f:\arduino_build_633245/sketch/defs.h" "-IC:\Arduino\hardware\teensy\avr\cores\teensy3" "C:\Arduino\hardware\teensy\avr\cores\teensy3\nonstd.c" -o "f:\arduino_build_633245\core\nonstd.c.o"
    C:\Arduino\hardware\teensy\avr\cores\teensy3\nonstd.c: In function 'dtostrf':
    
    C:\Arduino\hardware\teensy\avr\cores\teensy3\nonstd.c:174:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    
        if (newDecimalPoint - decpt == precision + 1) decpt++;
    
                                    ^
    
    "C:\Arduino\hardware\teensy/../tools/arm/bin/arm-none-eabi-gcc" -c -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD  -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -D__MK66FX1M0__ -DTEENSYDUINO=137 -DARDUINO=10803 -DF_CPU=240000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "@f:\arduino_build_633245/sketch/defs.h" "-IC:\Arduino\hardware\teensy\avr\cores\teensy3" "C:\Arduino\hardware\teensy\avr\cores\teensy3\pins_teensy.c" -o "f:\arduino_build_633245\core\pins_teensy.c.o"
    C:\Arduino\hardware\teensy\avr\cores\teensy3\pins_teensy.c: In function 'analogWrite':
    
    C:\Arduino\hardware\teensy\avr\cores\teensy3\pins_teensy.c:727:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    
      } else if (val >= max) {
    Just add -Wextra to the GCC-Commandline to see them.
    Last edited by Frank B; 06-07-2017 at 07:00 PM.

  2. #2
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    Just found a third type :
    comparison is always false due to limited range of data type [-Wtype-limits]
    and
    comparison of unsigned expression < 0 is always false [-Wtype-limits]

    examples:
    Code:
    \Arduino\hardware\teensy\avr\cores\teensy3\Stream.cpp:184:8: warning: comparison is always false due to limited range of data type [-Wtype-limits]
    
       if(c < 0)
    
            ^
    
    "C:\Arduino\hardware\teensy/../tools/arm/bin/arm-none-eabi-g++" -c -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -fno-exceptions -felide-constructors -std=gnu++11 -fno-rtti -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -D__MK66FX1M0__ -DTEENSYDUINO=137 -DARDUINO=10803 -DF_CPU=240000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "@f:\arduino_build_633245/sketch/defs.h" "-IC:\Arduino\hardware\teensy\avr\cores\teensy3" "C:\Arduino\hardware\teensy\avr\cores\teensy3\Tone.cpp" -o "f:\arduino_build_633245\core\Tone.cpp.o"
    "C:\Arduino\hardware\teensy/../tools/arm/bin/arm-none-eabi-g++" -c -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -fno-exceptions -felide-constructors -std=gnu++11 -fno-rtti -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -D__MK66FX1M0__ -DTEENSYDUINO=137 -DARDUINO=10803 -DF_CPU=240000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "@f:\arduino_build_633245/sketch/defs.h" "-IC:\Arduino\hardware\teensy\avr\cores\teensy3" "C:\Arduino\hardware\teensy\avr\cores\teensy3\WMath.cpp" -o "f:\arduino_build_633245\core\WMath.cpp.o"
    "C:\Arduino\hardware\teensy/../tools/arm/bin/arm-none-eabi-g++" -c -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -fno-exceptions -felide-constructors -std=gnu++11 -fno-rtti -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -D__MK66FX1M0__ -DTEENSYDUINO=137 -DARDUINO=10803 -DF_CPU=240000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "@f:\arduino_build_633245/sketch/defs.h" "-IC:\Arduino\hardware\teensy\avr\cores\teensy3" "C:\Arduino\hardware\teensy\avr\cores\teensy3\WString.cpp" -o "f:\arduino_build_633245\core\WString.cpp.o"
    C:\Arduino\hardware\teensy\avr\cores\teensy3\WString.cpp: In member function 'int String::lastIndexOf(char, unsigned int) const':
    
    C:\Arduino\hardware\teensy\avr\cores\teensy3\WString.cpp:563:36: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
    
      if (fromIndex >= len || fromIndex < 0) return -1;
    
                                        ^
    
    C:\Arduino\hardware\teensy\avr\cores\teensy3\WString.cpp: In member function 'int String::lastIndexOf(const String&, unsigned int) const':
    
    C:\Arduino\hardware\teensy\avr\cores\teensy3\WString.cpp:579:61: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
    
        if (s2.len == 0 || len == 0 || s2.len > len || fromIndex < 0) return -1;
    Edit:
    Created a pull-request for these (in this post only)
    Last edited by Frank B; 06-07-2017 at 06:44 PM.

Posting Permissions

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