У меня 5.11 такая конструкция
Код
#include <stdint.h>
typedef union {
uint32_t DPT_all;
struct {
uint32_t A8 :8;
uint32_t A3 :3;
uint32_t B8 :8;
uint32_t B3 :3;
uint32_t D :8;
}part;
}dpt_word;
static dpt_word DPT_word;
uint32_t foo(void)
{
DPT_word.DPT_all=0;
DPT_word.part.A8 = 255;
DPT_word.part.A3 = 0;
DPT_word.part.B8 = 255;
DPT_word.part.B3 = 0;
DPT_word.part.D = 255;
return DPT_word.DPT_all;
}
volatile dpt_word DPT_word1;
uint32_t foo1(void)
{
DPT_word1.DPT_all=0;
DPT_word1.part.A8 = 255;
DPT_word1.part.A3 = 0;
DPT_word1.part.B8 = 255;
DPT_word1.part.B3 = 0;
DPT_word1.part.D = 255;
return DPT_word1.DPT_all;
}
компилится верно в первом случае компилер все выкидывает и возвращает коснтанту 0x3fc7f8ff
с volatile весь код есть и он правильный.