C++ binary constant/literal

后端 未结 7 2159
-上瘾入骨i
-上瘾入骨i 2020-12-14 21:09

I\'m using a well known template to allow binary constants

template< unsigned long long N >
struct binary
{
  enum { value = (N % 10) + 2 * binary<          


        
7条回答
  •  孤城傲影
    2020-12-14 21:35

    Technically it is not C nor C++, it is a GCC specific extension, but GCC allows binary constants as seen here:

     The following statements are identical:
    
     i =       42;
     i =     0x2a;
     i =      052;
     i = 0b101010;
    

    Hope that helps. Some Intel compilers and I am sure others, implement some of the GNU extensions. Maybe you are lucky.

提交回复
热议问题