The program has a function that, depending on the selected address, writes the transferred value to some variables. It looks like this:
int reg_write(uint16_t addr, uint16_t value) { switch(addr) { case S0_1_A: return write_to(value, 0, 1, SA); case S0_2_B: return write_to(value, 0, 2, SB); . . . case S1_12_B: return write_to(value, 1, 12, SB); default: return ERROR_CODE; } } That is, there is a range of addresses and, depending on the address, I write to some variable of one of the 2 structures s0 or s1. That is, for example:
int write(uint16_t value, int sn, int n, enum SE se) { if(se == SA) s[sn].a[n] = value; else s[sn].b[n] = value; } The example is conditional, in fact, I have a lot more structures and variables. The Sxxx constants generally have arbitrary values, but for one structure S they go strictly in order, but there are “holes” (S0_1_A, S0_1_B, S0_2_A, S0_5_A, S0_5B), followed by index 2 immediately. 5 addresses. Question: how can you simplify the recording of a switch-case as much as possible?
GCC compiler, you can use any means. It may even be some kind of code generation, but preferably as simple as possible and, if possible, in C, not in C ++.
std::map<uint16_t, std::pair<uint8_t, uint8_t> = {{S0_1, {0 ,1}}, ...}- user1056837SX_Xequal to? Can thesnandnvalues be pulled out by overlaying a bit mask? - Anton Shchyrov 2:41 pm