0

When developing the firmware for STM32 in IAR, I encountered the following:

typedef enum ll{
  A = 0b00000000000000000000000000000000,
  B = 0b00000000000000000000000000000011,
} lol;

Error[Pe067]: expected a "}" PROJ\Core\Src\main.c 72 (2d line)

But,

typedef enum ll{
  A = 0x00000000,
  B = 0x11111111,
} lol;

is compile successfully. I know all of this code work in another IDE n compilers. But what happens in my case? Why number with 0b brings errors? Maybe needed set some configure for compiler?

  • 3
    Note that the `0b` prefix for binary numbers is not a standard part of the C language, but some implementations support it as an extension. – Ian Abbott Aug 23 '21 at 10:44
  • Does this answer your question? [What does "0b" and "0x" stand for when assigning binary and hex?](https://stackoverflow.com/questions/57605226/what-does-0b-and-0x-stand-for-when-assigning-binary-and-hex) – Krishna Kanth Yenumula Aug 23 '21 at 10:47
  • Does this answer your question? [Why doesn't C have binary literals?](https://stackoverflow.com/questions/18244726/why-doesnt-c-have-binary-literals) – phuclv Aug 23 '21 at 10:49
  • The working draft of the next version of the C standard (C23) does have these binary literals. – Ian Abbott Aug 23 '21 at 10:51
  • IAR does not support binary constans. – 0___________ Aug 23 '21 at 10:58
  • 2
    This is mentioned in IAR's [Technical Note 46979](https://www.iar.com/knowledge/support/technical-notes/compiler/any-binary-notation-in-c-source/). – Ian Abbott Aug 23 '21 at 11:09

2 Answers2

3

Binary literals (i.e. integers with the 0b prefix, such as 0b010101) are not part of the (standard) C language. However, they are part of C++ (since C++14), and some compilers (notably GCC) support them as an extension in C.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
1

IAR does not support binary constants as they are not the part of the C standard.

0___________
  • 60,014
  • 4
  • 34
  • 74