• [^] # Re: Clang vs GCC

    Posté par (site web personnel) . En réponse à la dépêche LLVM 3.2 et Clang 3.2 publiés. Évalué à 2.

    Test avec g++ 4.6.3

    #include <iostream>
    int main() {
     float x = 1.0;
     x *= 0,75;
     std::cout << x << std::endl;
    }
    
    
    $ g++ -o virgule virgule.cpp && ./virgule
    0
    $ g++ -Wall -o virgule virgule.cpp && ./virgule
    virgule.cpp: In function ‘int main()’:
    virgule.cpp:4:12: attention : right operand of comma operator has no effect [-Wunused-value]
    0
    $ g++ -Wunused-value -o virgule virgule.cpp && ./virgule 
    virgule.cpp: In function ‘int main()’:
    virgule.cpp:4:12: attention : right operand of comma operator has no effect [-Wunused-value]
    0
    
    

    Remplaçons la ligne par :

     x *= 0,x=75;
    
    
    $ g++ -Wall -o virgule virgule.cpp && ./virgule
    75
    
    

    Et c'est aussi valable en C :

    #include "stdio.h"
    int main() {
     float x = 1.0;
     x *= 0,x=75;
     printf("%f\n",x);
    }
    
    
    $ gcc -Wall -o virgule virgule.cpp && ./virgule
    75.000000