I am getting this warning while compiling the library.
warning: conversion to ‘unsigned char’ from ‘int’ may alter its value
This prevents us from using compiler option -Werror.
Can anyone suggest the way to fix this warning ???
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Shoot in the dark:
Use a
static_castto instruct the compiler that you know that the conversion will not result into a truncation:int i; unsigned char c = static_cast<unsigned char>(i);If you are not so sure, check out
boost::numeric_cast.It’s equivalent to
static_castin this case, but much more explicit (easier to grep / search for numeric conversions). Also, it performs bound checkings.