Search code examples
c++builderc++builder-xe4

C++Builder > binary number 0b1 causes error E2141


I am using C++ Builder XE4.

I am trying to use a binary number such as 0b1 in my code.

Following is the code I tried:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    int num = 0b11;
}

The above causes a compiler error:

Unit1.cpp(19): E2141 Declaration syntax error

Does C++Builder support binary numeration like this?

I confirmed that 0x11 works in C++Builder.

I also confirmed that 0b11 can be used in IDEOne using C++:

http://ideone.com/oy4aIZ


Solution

  • Binary notation of integer literals is a new feature in C++14. However, no C++Builder version has a C++14 compiler at this time.

    In XE4, the Win32 compiler and OSX compiler do not support C++11 at all (a 32bit C++11 compiler was added in 10.0 Seattle). The Win64 compiler supports C++11, though.

    The current C++Builder compilers support only decimal, octal, and hex. See Embarcadero's documentation for details: Integer Constants