On Wed, Oct 28, 2020 at 11:44:35AM +0100, Adam Kandur wrote:
>
> hi everyone, i'm new in c programming. i tried to read sources but stuck with enum.
> as i know, enum is mainly used to assign names to integral constants. but i don't understand, for example, this code
> ----------------------------------------------
> enum term_mode {
> MODE_WRAP = 1 << 0,
> MODE_INSERT = 1 << 1,
> MODE_ALTSCREEN = 1 << 2,
> MODE_CRLF = 1 << 3,
> MODE_ECHO = 1 << 4,
> MODE_PRINT = 1 << 5,
> MODE_UTF8 = 1 << 6,
> };
> ----------------------------------------------why not simply write ?
> ----------------------------------------------
> enum term_mode {
> MODE_WRAP = 1,
> MODE_INSERT = 2,
> MODE_ALTSCREEN = 4,
> MODE_CRLF = 8,
> MODE_ECHO = 16,
> MODE_PRINT = 32,
> MODE_UTF8 = 64,
> };
> ----------------------------------------------
>
Hi,
They are the same and are coding-style.
The bitshift typically hints that the value is used as a bitmask somewhere.
--
Kind regards,
Hiltjo
Received on Wed Oct 28 2020 - 11:54:36 CET