Warning about narrowing conversion when using okapilib chassis factory

When compiling my chassis factory code, I encounter this warning:

warning: narrowing conversion of ‘-(int)driveFR_port’ from ‘int’ to ‘int8_t {aka signed char}’
inside { } [-Wnarrowing]
{driveFL_port, driveBL_port}, {(-driveFR_port), (-driveBR_port)}

I have tried defining my port number as both an int and an int8_t. I need to leave them positive for other elements of my code, but my understanding is that okapilib wants reversed ports to be negative, so I am trying to negate them here. Any help is appreciated.

It’s most likely just a useless warning that you can safely ignore.
Just don’t do anything special, don’t manually cast, just use int.
Maybe show us your code, but its probably not an issue.

Here is the relevant coding segment:

const int driveFR_port = 1;
const int driveFL_port = 2;
const int driveBR_port = 3;
const int driveBL_port = 4;
const int tray_port = 5;
const int lift_port = 6;
const int intakeR_port = 7;
const int intakeL_port = 8;
auto driveController = ChassisControllerFactory::create(
{driveFL_port, driveBL_port}, {(-driveFR_port), (-driveBR_port)},
{4_in, 10.5_in}

I may just let it be until okapilib 4 comes out; I will just have to deal with the madness of always having a warning :smile:

Check out the latest RC here: https://github.com/OkapiLib/OkapiLib/releases/download/4.0.0-RC2/okapilib@4.0.0-RC2.zip
Docs have moved: https://okapilib.github.io/OkapiLib/index.html
Please report any issues here: https://github.com/OkapiLib/OkapiLib

If you are unsure how to install the template, take a look at the PROS docs or Theo’s post here: Three Encoder Skid Steer Model

Thanks for helping make OkapiLib better!


Have you tried casting to int8_t instead of int here?

Yes, and it returns the same error for the negative numbers.

Edit: nevermind, this worked great, just messed up the casting