ARTICLE AD BOX
When compiling code that assigns a value to a 24-bit field, GCC fails with an error if using -Werror=conversion. Other then turning off the warning explicitly, is there a way to cast the assignment to avoid the warning being generated?
using DayOffsetLocal = uint32_t; class TimerPeriod { private: DayOffsetLocal startTime: 24; }; startTime = (temp16*60U) & 0xFFFFFFU;I tried using
startTime = static_cast<decltype(startTime)>((temp16*60U) & 0xFFFFFFU);But that still generates
error: conversion from 'Timers::DayOffsetLocal' {aka 'long unsigned int'} to 'unsigned int:24' may change value [-Werror=conversion]