2011-11-21 17 views
21

Estoy usando g ++ versión 4.1.2 en una caja RHEL 5.7 x86_64. Esto funciona perfectamente con la versión 4.4.5 de g ++ que viene con RHEL 6.0 x86_64. ¿Qué significa este error de compilación y cómo lo solucionas?error: sufijo no válido "b11111111111111111111111111111111" en la constante de enteros

[[email protected] C]$ g++ -Wall -o binary ./binary.cpp 
./binary.cpp:2:5: error: invalid suffix "b11111111111111111111111111111111" on integer constant 
./binary.cpp:3:5: error: invalid suffix "b11111111111111111111111111111110" on integer constant 
./binary.cpp:4:5: error: invalid suffix "b11111111111111111111111111111100" on integer constant 
./binary.cpp:5:5: error: invalid suffix "b11111111111111111111111111111000" on integer constant 
./binary.cpp:6:5: error: invalid suffix "b11111111111111111111111111110000" on integer constant 
./binary.cpp:7:5: error: invalid suffix "b11111111111111111111111111100000" on integer constant 
./binary.cpp:8:5: error: invalid suffix "b11111111111111111111111111000000" on integer constant 
./binary.cpp:9:5: error: invalid suffix "b11111111111111111111111110000000" on integer constant 
./binary.cpp:10:5: error: invalid suffix "b11111111111111111111111100000000" on integer constant 
./binary.cpp:11:5: error: invalid suffix "b11111111111111111111111000000000" on integer constant 
./binary.cpp:12:5: error: invalid suffix "b11111111111111111111110000000000" on integer constant 
./binary.cpp:13:5: error: invalid suffix "b11111111111111111111100000000000" on integer constant 
./binary.cpp:14:5: error: invalid suffix "b11111111111111111111000000000000" on integer constant 
./binary.cpp:15:5: error: invalid suffix "b11111111111111111110000000000000" on integer constant 
./binary.cpp:16:5: error: invalid suffix "b11111111111111111100000000000000" on integer constant 
./binary.cpp:17:5: error: invalid suffix "b11111111111111111000000000000000" on integer constant 
./binary.cpp:18:5: error: invalid suffix "b11111111111111110000000000000000" on integer constant 
./binary.cpp:19:5: error: invalid suffix "b11111111111111100000000000000000" on integer constant 
./binary.cpp:20:5: error: invalid suffix "b11111111111111000000000000000000" on integer constant 
./binary.cpp:21:5: error: invalid suffix "b11111111111110000000000000000000" on integer constant 
./binary.cpp:22:5: error: invalid suffix "b11111111111100000000000000000000" on integer constant 
./binary.cpp:23:5: error: invalid suffix "b11111111111000000000000000000000" on integer constant 
./binary.cpp:24:5: error: invalid suffix "b11111111110000000000000000000000" on integer constant 
./binary.cpp:25:5: error: invalid suffix "b11111111100000000000000000000000" on integer constant 
./binary.cpp:26:5: error: invalid suffix "b11111111000000000000000000000000" on integer constant 
./binary.cpp:27:5: error: invalid suffix "b11111110000000000000000000000000" on integer constant 
./binary.cpp:28:5: error: invalid suffix "b11111100000000000000000000000000" on integer constant 
./binary.cpp:29:5: error: invalid suffix "b11111000000000000000000000000000" on integer constant 
./binary.cpp:30:5: error: invalid suffix "b11110000000000000000000000000000" on integer constant 
./binary.cpp:31:5: error: invalid suffix "b11100000000000000000000000000000" on integer constant 
./binary.cpp:32:5: error: invalid suffix "b11000000000000000000000000000000" on integer constant 
./binary.cpp:33:5: error: invalid suffix "b10000000000000000000000000000000" on integer constant 

El código:

static int s_bitCountMask[32] = { 
    0b11111111111111111111111111111111, 
    0b11111111111111111111111111111110, 
    0b11111111111111111111111111111100, 
    0b11111111111111111111111111111000, 
    0b11111111111111111111111111110000, 
    0b11111111111111111111111111100000, 
    0b11111111111111111111111111000000, 
    0b11111111111111111111111110000000, 
    0b11111111111111111111111100000000, 
    0b11111111111111111111111000000000, 
    0b11111111111111111111110000000000, 
    0b11111111111111111111100000000000, 
    0b11111111111111111111000000000000, 
    0b11111111111111111110000000000000, 
    0b11111111111111111100000000000000, 
    0b11111111111111111000000000000000, 
    0b11111111111111110000000000000000, 
    0b11111111111111100000000000000000, 
    0b11111111111111000000000000000000, 
    0b11111111111110000000000000000000, 
    0b11111111111100000000000000000000, 
    0b11111111111000000000000000000000, 
    0b11111111110000000000000000000000, 
    0b11111111100000000000000000000000, 
    0b11111111000000000000000000000000, 
    0b11111110000000000000000000000000, 
    0b11111100000000000000000000000000, 
    0b11111000000000000000000000000000, 
    0b11110000000000000000000000000000, 
    0b11100000000000000000000000000000, 
    0b11000000000000000000000000000000, 
    0b10000000000000000000000000000000, 
}; 

#include <stdio.h> 

int main(int argc, char *argv[]) 
{ 
    for (int i = 0; i < 32; i++) { 
     printf("%d\n",s_bitCountMask[i]); 
    } 
} 
+29

+1 porque el error simplemente se ve increíble. – slhck

+3

¿Cómo no puedo hacer clic en un título como ese? – Mysticial

+3

No es una respuesta, pero ¿no sería más fácil calcular la matriz en tiempo de ejecución? –

Respuesta

29

Significa la mayor verison de g ++ no aceptará el sintaxis constante binaria 0b000. Puede volver a escribir los números en lugar hexagonal - binario se traduce fácilmente en hexadecimal cuatro bits a la vez:

0xffffffff, 0xfffffffe, 0xfffffffc, 0xfffffff8, 
0xfffffff0, 0xffffffe0, 0xffffffc0, 0xffffff80, 
0xffffff00, 0xfffffe00, 0xfffffc00, 0xfffff800, 
0xfffff000, 0xffffe000, 0xffffc000, 0xffff8000, 
0xffff0000, 0xfffe0000, 0xfffc0000, 0xfff80000, 
0xfff00000, 0xffe00000, 0xffc00000, 0xff800000, 
0xff000000, 0xfe000000, 0xfc000000, 0xf8000000, 
0xf0000000, 0xe0000000, 0xc0000000, 0x80000000 
+6

Por cierto, el formato binario está disponible solo a partir de [gcc 4.3] (http://gcc.gnu.org/gcc-4.3/changes.html). – kennytm

8

Rup tiene la respuesta correcta a esta. Pero voy a añadir esto:

Dependiendo de cómo se está accediendo a esa mesa, que podría ser más apropiado para generar el valor justo en el lugar con esto:

unsigned mask = ~((1 << index) - 1); 
unsigned mask = -1 << index;   // Better solution (by Rup) 

Como alternativa, también se puede declarar la tabla de la siguiente manera:

static int s_bitCountMask[32] = { 
    -1 << 0, 
    -1 << 1, 
    -1 << 2, 
    -1 << 3, 

    ... 

    -1 << 31, 
}; 

* Suponiendo que -1 es todo lo que uno bits (que lo es en casi todas las máquinas de ahora).

+0

:-) Lo habría editado si hubiera podido pensarlo a tiempo. Mi intento iba a ser '-1 << index' o' (~ 0) << index'. – Rup

+2

Debe hacerlo sin firmar. –

+0

Ah, lo pasé por alto también. Actualizado mi respuesta. – Mysticial

Cuestiones relacionadas