My C course is several years old and I don’t remember very clearly one thing.
I’ve defined an array: unsigned char cur_but_solo[96]={0}; In my code, sometimes I set one value of this array to 1 or reset to 0. At the end, I want to check is this array is still equal to {0} without using a for loop. Is there a “clean” way to proceed?
Initially I considered to propose a union (sometimes also called aggregate), because access to individual bits is much faster (single assembler instruction)
But for your usecase it doesn’t help, because you don’t access the bits directly, but via an index (button number variable) - unions cannot be accessed this way (in other words: you have to statically specify the bit number/union element which should be accessed)
Not any more. I think I made a 256-bit long bitfield recently to test it out
NSunier I’ve written a big explanation of structs unions and bitfields in another thread, you should check it out! Just search for those three words in posts made by me, you’ll find it.
Edit: BTW, if you missed the HLP functions, it’s time to read the Function Reference again!
NSunier I’ve written a big explanation of structs unions and bitfields in another thread, you should check it out! Just search for those three words in posts made by me, you’ll find it.
typedef and union are actually two separate things, but TK is using them together. I’m guessing that you’re looking at a bitfield. Here’s an example, I’ll break it down.