* Andreas Tille <andr...@an3as.eu>, 2016-08-13, 21:11:
/build/hyphy-2.2.6+dfsg/src/gui/HYChartWindow.cpp:113:1: error: narrowing 
conversion of '3.0599999999999998e+1' from 'double' to 'unsigned char' inside { 
} [-Wnarrowing]
...

Which is caused by:


_HYColor            chartColors [HY_CHART_COLOR_COUNT] = {
   {255*.94, 255*.12, 255*.11 },//(Red)
   {255*.41, 255*.46, 255*.91 },//(Evening Blue)
   {255    , 255*.91, 255*.34 },//(Banana)
   {255*.18, 255*.55, 255*.13 },//(Clover)
   {255*.55, 255*.38, 255*.21 },//(Dirt)
   {255*.42, 255*.09, 255*.69 },//(Royal Violet)
   {255*.09, 255*.29, 255*.51 },//(Sea Blue)
   {255   ,  255*.57, 255*.09 },//(Orange)
   {255*.67, 255*.67, 255*.67 },//(Concrete)
   {255*.85, 255*.27, 255*.42 } //(Carnation)
};


the narrowing conversion in this case is absolutely intended here obviously. Is there any more elegant solution for these case than something like

   s:\.\([0-9][0-9]\):\1/100:g

?

Your alternatives are:
- Use -Wno-narrowing to suppress this error.
- Define constructor for _HYColor and then use it.
- Make explicit typecasts from double to int.

Neither of them is particularly elegant...

Either way, you might want to define a temporary macro to make this less repetitive, e.g.:

_HYColor            chartColors [HY_CHART_COLOR_COUNT] = {
#define t(r, g, b) { 255 * r / 100, 255 * g / 100, 255 * b / 100 }
   t(94, 12, 11), //(Red)
   t(41, 46, 91), //(Evening Blue)
   t(100, 91, 34), //(Banana)
   // ...
#undef t
};


BTW, _HYColor is not a good name for a structure. In C++, identifiers that begin with an underscore are reserved.

--
Jakub Wilk

Reply via email to