Je me demandais ce que la différence entre:Pourquoi gcc produit-il des binaires compilés différents pour des programmes utilisant différentes formes de littéraux entiers?
int a = 0b00000100;
int a = 0x04;
int a = 4;
Lorsque compilé avec gcc.
Je semble obtenir un binaire différent lors de la compilation avec ce qui semble être le même nombre, juste dans des notations différentes. Quand j'exécute objdump cependant, il ne semble y avoir aucune différence. Quelqu'un pourrait-il me dire ce qui se passe?
Ceci est mon sortie:
[email protected]:[~]: cat testbin.c && echo && cat testbin2.c
#include "stdio.h"
int main() {
int a = 0b00000100;
int b = 0x05;
int c = 6;
printf("%d - %d - %d\n", a, b, c);
return (0);
}
#include "stdio.h"
int main() {
int a = 4;
int b = 5;
int c = 6;
printf("%d - %d - %d\n", a, b, c);
return (0);
}
[email protected]:[~]: gcc testbin.c -o testbin
[email protected]:[~]: gcc testbin2.c -o testbin2
[email protected]:[~]: md5sum testbin testbin2
fd6aaa31bdf685ea9444e1edc209565e testbin
3a3fc241bfc2917ee29999b5befecd2a testbin2
[email protected]:[~]: objdump -d testbin > testbin.obj && objdump -d testbin2 > testbin2.obj
[email protected]:[~]: diff testbin.obj testbin2.obj
2c2
< testbin: file format elf64-x86-64
---
> testbin2: file format elf64-x86-64
[email protected]:[~]: gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 6.3.0-18' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-6 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 6.3.0 20170516 (Debian 6.3.0-18)
[email protected]:[~]:
Notez que les executables sont différents, ils ont des hash, mais objdump -d
ne montre pas quelque chose de différent.
Ce ne sont pas les mêmes fichiers. Pourquoi vous attendez-vous à ce que la somme de contrôle soit la même? https://en.wikipedia.org/wiki/Md5sum –
Notez que '0b00000100;' n'est pas standard C. – chux
@KenWhite Je ne me souviens pas qu'il compilé les noms de fichiers originaux dans. –