setChannels(16) generates warning

For a module I am working on

outputs[PULSES_OUTPUT].setChannels(16);

causes a warning during build

In member function 'void rack::engine::Port::setChannels(uint8_t)',
    inlined from 'void TuringMachineModule::processParams(const rack::engine::Module::ProcessArgs&)' at
 src/TuringMachine.cpp:449:43,
    inlined from 'virtual void TuringMachineModule::process(const rack::engine::Module::ProcessArgs&)' at src/TuringMachine.cpp:505:26:
C:/Data/Cpp/Rack-SDK/include/engine/Port.hpp:163:35: warning: array subscript 16 is above array bounds of 'float [16]' [-Warray-bounds=]
  163 |                         voltages[c] = 0.f;
      |                         ~~~~~~~~~~^
C:/Data/Cpp/Rack-SDK/include/engine/Port.hpp: In member function 'virtual void TuringMachineModule::process(const rack::engine::Module::ProcessArgs&)':
C:/Data/Cpp/Rack-SDK/include/engine/Port.hpp:18:23: note: while referencing 'rack::engine::Port::<unnamed union>::voltages'
   18 |                 float voltages[PORT_MAX_CHANNELS] = {};
      |                       ^~~~~~~~

So as of now I’ve changed my code to simply set the channels property of my output-port without calling setChannels

outputs[PULSES_OUTPUT].channels = 16;

yep…

1 Like

You can suppress a single warning, see Annoying warnings on Windows build (engine/Port.hpp) - #15 by Ahornberg

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds"
    voltages[c] = 0.f;
#pragma GCC diagnostic pop
2 Likes

Thanks I saw you wrote that in one of the posts Dan included so I did the following, and warning is gone:

        #pragma GCC diagnostic push
        #pragma GCC diagnostic ignored "-Warray-bounds"
        outputs[PULSES_OUTPUT].setChannels(16);
        #pragma GCC diagnostic pop