Hi, Fantastic post!!!
I adopted a lot of the flags pointed to by this post for my project. I have several bit fields in structures. I am running into issues with bit fileds and -Werror=conversion
flag. An example is shown below:
typedef struct led_control
{
uint8_t LED_IND : 1;
uint8_t ICL_IND : 2;
uint8_t LED_DRV : 1;
uint8_t ICL_DRV : 2;
}led_control;
I get an error when i do something like this,
void optical_setDrvCurrent(uint8_t current, optical* opt)
{
opt->_led_control.ICL_DRV = current;
optical_virtualWrite(AS726X_LED_CONTROL, get_led_control(&opt->_led_control));
}
The compile error points to the opt->_led_control.ICL_DRV = current;
statement.
error: conversion from 'uint8_t' {aka 'unsigned char'} to 'unsigned char:2' may change value [-Werror=conversion]
The only way to get past these errors (I use -Werror
flag too) is to use bit masks and shifts, but that completely defeats the purpose of the bit field. Any thoughts on how to work around this?
Thanks,
Rajah