RT, the last assignment of this structure will overwrite the previous assignment, so I’m curious as to what scenarios this kind of thing is generally used in?
The original purpose was to save memory. If you think about it, C language only began to be used on a large scale in the 1980s, and memory was very precious at that time.
However, it is not very concise to write this way, and the efficiency of this code in PC is the same as directly fetching each byte through bit shifting. Just an example, don't get too hung up on it.
Save memory and facilitate access to high and low bytes
The original purpose was to save memory. If you think about it, C language only began to be used on a large scale in the 1980s, and memory was very precious at that time.
Can provide different access interfaces to the same piece of data. . .
For example, when you were doing embedded work, you could write like this:
However, it is not very concise to write this way, and the efficiency of this code in PC is the same as directly fetching each byte through bit shifting. Just an example, don't get too hung up on it.
Generally used to determine the big and small ends
It is often used in embedded development. Let me give an example here, which is similar to @zonxin’s above
To read the entire register, you can read value. To write different bit-filed, use reg_des_bit to write.