2009-02-03 45 views
5

Duplicar posibles:
Can I make GCC warn on passing too-wide types to functions?Diferencia entre -Wconversion entre gcc y g ++

Considérese el siguiente programa de prueba:

static void func(int a) 
{ 
} 

int main() 
{ 
    unsigned int b = 42; 

    func(b); 

    return 0; 
} 

Compilar con gcc:

 
[email protected]:~/projects$ gcc -Wconversion testit.c 
testit.c: In function âmainâ: 
testit.c:11: warning: passing argument 1 of âfuncâ as signed due to prototype 
[email protected]:~/projects$ 

Pero, en g ++ No hay ninguna advertencia !:

 
[email protected]:~/projects$ g++ -Wconversion testit.c 
[email protected]:~/projects$ 

¿Cuál es la razón de esto y hay alguna manera de conseguir la misma advertencia al compilar código C++?

Respuesta

4

De the documentation para -Wconversion:

advertencias acerca de las conversiones entre números enteros con y sin signo son desactivados por defecto en C++ a menos -Wsign conversión está explícitamente habilitado

Parece que también necesitará una versión suficientemente nueva de GCC. Tengo la versión 4.0.1, y no reconoce -Wsign-conversion.