Boost logo

Boost :

From: Pete Becker (petebecker_at_[hidden])
Date: 2002-05-23 08:31:07


At 12:53 PM 5/23/2002 +0100, John Maddock wrote:
> > enum _Ios_Seekdir { _M_ios_seekdir_end = 1L << 16 };
> >
> > // 27.4.2.1.5 Type seekdir
> > typedef _Ios_Seekdir seekdir;
> > static const seekdir beg = seekdir(0);
> > static const seekdir cur = seekdir(SEEK_CUR);
> > static const seekdir end = seekdir(SEEK_END);
>
>What? You're kidding me: surely this can't be legal code, none of
>ios_base::beg, cur or end are valid values of ios_base::seekdir are they?

The representation of an enumeration must have enough bits to hold the
largest declared value. So with _Ios_Seekdir having an enumerator with the
value 1 << 16, the enum must have 16 bits. As long as SEEK_CUR and SEEK_END
fit in 16 bits they are legal values.

The reason for that rule is to allow things like:

enum flags { none = 0, first = 0x01, second = 0x02, third = 0x04 };
flags fst = flags(first | second | third);

        -- Pete

Dinkumware, Ltd.
"Genuine Software"


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk