Re: [Newbie] BPL14 & Bit vs Struct

From: George (greerga@CIRCLEMUD.ORG)
Date: 06/22/98


On Mon, 22 Jun 1998, Lord Kyu wrote:

>I appreciate J.  Elson's work he did to provide is with
>CircleMUD, as well as those who have helped him to improve it's code.

I know you didn't do this intentionally, but you're using past tense. :)

>        Going back to a conversation that was going on sometime last week,
>I was wondering which would be better in certain cases when using a
>seperate struct, or using 128 bit. I am tempted at add a few extra
>structs, just to neaten up my stat command, as well as some of the code I
>have. Or the other choice I have is going to 128 bit, which by the way
>things seem, won't neaten up the code, but will provide me with the extra
>space I need. This may be a newbish question, I was just wondering in what
>cases each would be better to use. Thanks for your time, once again, great
>job.

Try bitfields, if you want something new. (unsigned this_is_a_bit : 1)

It'd take a lot of work to do, but you won't have an arbitrary
limit of 32 bits for expandability.  You can't do an array of bits (or at
least, I wasn't successful) but you can name all the bits whatever you
want.  So:

if (PLR_FLAGGED(ch, PLR_CRIMINAL))

becomes

if (ch->bits.criminal)

or if you prefer macros:

if (GET_BIT(ch, criminal))      (Leaving IS_SET for compatibility if you want.)

with '#define GET_BIT(ch, bitname)      ((ch)->bits.##bitname)'

Then adding a new flag becomes as easy as adding a variable to a struct.

--

Or if you want the 'quick & easy' method, change all of the bitvector
variables to 'long long' or '__longlong' depending on your compiler (if it
supports it) to have at least 64 bits.  GCC is known to generate awful (and
sometimes wrong) code for 'long long' at least in version 2.7.2.3.

--
George Greer, greerga@circlemud.org | Genius may have its limitations, but
http://patches.van.ml.org/          | stupidity is not thus handicapped.
http://www.van.ml.org/CircleMUD/    |                  -- Elbert Hubbard


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST