CThinker wrote:I normally just create a "union". The bit field parts are there for visual debugging, but in the code, the 'parts' are accessed/modified using the less readable shift/and/or operations.
As long as you're disciplined enough to not access the union fields in the code, that seems even better.
I wouldn't choose that on a project where there were many developers involved though. Too much chance for problems.
rbarreira wrote:It seems most people aren't understanding what the OP meant. Notice the part where he talks about a cast and a debugger, he's just talking about creating an unused struct for the purpose of being viewed in a debugger.
It's ok if you know the architecture. But nothing in the spec says the bit variables start from either the MSB or LSB end. So this is definitely a non-portable solution.
rbarreira wrote:It seems most people aren't understanding what the OP meant. Notice the part where he talks about a cast and a debugger, he's just talking about creating an unused struct for the purpose of being viewed in a debugger.
It's ok if you know the architecture. But nothing in the spec says the bit variables start from either the MSB or LSB end. So this is definitely a non-portable solution.
It did take me a few tries to get it right and if I switch to another compiler or debugging environment it may well have to be changed, but I don't know any easier way of displaying packed data in an unpacked format
rbarreira wrote:It seems most people aren't understanding what the OP meant. Notice the part where he talks about a cast and a debugger, he's just talking about creating an unused struct for the purpose of being viewed in a debugger.
It's ok if you know the architecture. But nothing in the spec says the bit variables start from either the MSB or LSB end. So this is definitely a non-portable solution.
It did take me a few tries to get it right and if I switch to another compiler or debugging environment it may well have to be changed, but I don't know any easier way of displaying packed data in an unpacked format
How about writing a function to display it? You can call functions from gdb, and I imagine other debuggers would also allow this.
rbarreira wrote:It seems most people aren't understanding what the OP meant. Notice the part where he talks about a cast and a debugger, he's just talking about creating an unused struct for the purpose of being viewed in a debugger.
It's ok if you know the architecture. But nothing in the spec says the bit variables start from either the MSB or LSB end. So this is definitely a non-portable solution.
It did take me a few tries to get it right and if I switch to another compiler or debugging environment it may well have to be changed, but I don't know any easier way of displaying packed data in an unpacked format
How about writing a function to display it? You can call functions from gdb, and I imagine other debuggers would also allow this.