Re: [dev] newbie question

From: Adam Kandur <rndd_AT_tuta.io>
Date: Wed, 28 Oct 2020 12:05:23 +0100 (CET)

thank you for the answer



Oct 28, 2020, 10:54 by hiltjo_AT_codemadness.org:

> 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 - 12:05:23 CET

This archive was generated by hypermail 2.3.0 : Wed Oct 28 2020 - 12:12:08 CET