A use for bit fields

Discussion of chess software programming and technical issues.

Moderator: Ras

rbarreira
Posts: 900
Joined: Tue Apr 27, 2010 3:48 pm

Re: A use for bit fields

Post by rbarreira »

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.
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: A use for bit fields

Post by bob »

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.
jwes
Posts: 778
Joined: Sat Jul 01, 2006 7:11 am

Re: A use for bit fields

Post by jwes »

bob wrote:
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
AlvaroBegue
Posts: 931
Joined: Tue Mar 09, 2010 3:46 pm
Location: New York
Full name: Álvaro Begué (RuyDos)

Re: A use for bit fields

Post by AlvaroBegue »

jwes wrote:
bob wrote:
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.
jwes
Posts: 778
Joined: Sat Jul 01, 2006 7:11 am

Re: A use for bit fields

Post by jwes »

AlvaroBegue wrote:
jwes wrote:
bob wrote:
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.
That is possible but I would not call it easier.