[Python-ideas] IntFlags

random832 at fastmail.us random832 at fastmail.us
Thu Mar 5 16:58:44 CET 2015


On Wed, Mar 4, 2015, at 18:19, Andrew Barnert wrote:
> Think about how that extends to the result of |.

The value is either negative (is the complement of a finite set of bits)
or it isn't. Remember, the underlying representation is an int.

 Of course the answer
> depends on how you store ~ in the first place, but for most choices, str
> is not obvious. For example, using fixed-size unsigned with automatic
> highest-bit detection, for an enum with READ, WRITE, EXEC, STICKY,
> ~(READ) is the same value as (WRITE|EXEC|STICKY),

Why would that be the case?

> Yeah, open flags are especially screwy, where flags & 3 has a special
> non-bitmapped meaning but the rest of the bits are flags. There are other
> cases where multiple ints, only some of which are bitmaps, are packed as
> separate bitfields into the same int (e.g., TCP/IP headers), but I don't
> know of any others that pretend to be a single bitmap even though they
> aren't, so that's really a unique problem, which can be ignored.

Technically file modes have the file type field (flags & 0xF000) which
has some states that don't mean anything on common platforms.


More information about the Python-ideas mailing list