-2

I came accros this line of code:

#define BWAKUP              ('w' << 8)

What does it do? Its the same as:

#define BWAKUP              (167000)

In addition, another definition as :

#define CWAKUP                  (1 + BWAKUP)

is equivalent to :

#define CWAKUP                  (356000)

Right ?

ogs
  • 1,139
  • 8
  • 19
  • 42
  • No the same as `#define BWAKUP (0167<<8)`, 167 is the octal code for ASCII `'w'`. – Jean-Baptiste Yunès Dec 02 '15 at 09:33
  • Is `119*256=30464`. BTW depends on platform. – LPs Dec 02 '15 at 09:33
  • 1
    That depends on the character encoding of the target architecture. `'w'` is not `119` in all cases. *Why* it's there depends entirely on the context of the code, and there's not enough information in the question to know why `'w'` is used here. –  Dec 02 '15 at 09:33
  • 1
    @Jean-BaptisteYunès Can't be. That would be `0167` left shifted by 9 places, but we only shift by eight places. – fuz Dec 02 '15 at 09:38
  • How do you know it's the same as 167000? – user253751 Dec 02 '15 at 09:41
  • Basically, because I didn't understand and made mistakes during conversion. – ogs Dec 02 '15 at 11:06

2 Answers2

1

This line define a macro BWAKUP which expands to the expression ('w' << 8). That expression has, assuming your platform uses ASCII, the value 119 · 256 = 30464 which is not equal to 167000.Similarly, CWAKUP expands to (1 + ('w' << 8)) with the numeric value 30465, again assuming your system uses ASCII.

Without more context I can't tell you what the meaning of these macros is.

fuz
  • 88,405
  • 25
  • 200
  • 352
  • Ok then, `#define DWKUP (8 + BWAKUP)` equivalent to `#define DWKUP (8 + ('w' << 8)` would be equal to 30208 right ? – ogs Dec 02 '15 at 09:47
  • @SnP No. that's 30472. If you mean octal, than please say so. In C, octal numbers begin with a 0 to distinguish them from decimal numbers. – fuz Dec 02 '15 at 09:53
  • Ok, It was tough but I understand now ! Thank you so much – ogs Dec 02 '15 at 11:05
1

I came accros this line of code:

#define BWAKUP              ('w' << 8)

What does it do?

It defines the preprocessor macro BWAKUP as ('w' << 8). That means that whenever BWAKUP appears in the source code, it will be replaced with ('w' << 8). For example, printf("%i\n", BWAKUP); will be changed to printf("%i\n", ('w' << 8));.

Its the same as:

#define BWAKUP              (167000)

No, it's not.

In addition, another definition as :

#define CWAKUP                  (1 + BWAKUP)

is equivalent to :

#define CWAKUP                  (356000)

Right ?

No, but it would be equivalent to #define CWAKUP (1 + ('w' << 8)).

Community
  • 1
  • 1
user253751
  • 57,427
  • 7
  • 48
  • 90