Je ces deux fonctionsComportement étrange à l'aide getchar() et -O3
void set_dram_channel_width(int channel_width){
printf("one\n");
getchar();
}
void set_dram_transaction_granularity(int cacheline_size){
printf("two\n");
getchar();
}
//output:
one
f //my keyboard input
two
one
f //keyboard input
two
one
f //keyboard input
//No more calls
Puis-je changer les fonctions:
void set_dram_channel_width(int channel_width){
printf("one\n");
}
void set_dram_transaction_granularity(int cacheline_size){
printf("two\n");
getchar();
}
//output
one
two
f //keyboard input
//No more calls
Les deux fonctions sont appelées par un code externe, le code les deux programmes sont les mêmes, juste en changeant le getchar() j'obtiens ces deux sorties différentes. Est-ce possible ou il y a quelque chose qui ne va vraiment pas dans mon code?
Merci
Ceci est la sortie que j'obtiens avec GDB **
Pour le premier code
(gdb) break mem-dram.c:374
Breakpoint 1 at 0x71c810: file build/ALPHA_FS/mem/dramsim/mem-dram.c, line 374.
(gdb) break mem-dram.c:381
Breakpoint 2 at 0x71c7b0: file build/ALPHA_FS/mem/dramsim/mem-dram.c, line 381.
(gdb) run -d ./tmp/MyBench2/
one
f
[Switching to Thread 47368811512112 (LWP 17507)]
Breakpoint 1, set_dram_channel_width (channel_width=64)
(gdb) c
Continuing.
two
one
f
Breakpoint 2, set_dram_transaction_granularity (cacheline_size=64)
(gdb) c
Continuing.
Breakpoint 1, set_dram_channel_width (channel_width=8)
374 void set_dram_channel_width(int channel_width){
(gdb) c
Continuing.
two
one
f
Pour le second code
(gdb) break mem-dram.c:374
Breakpoint 1 at 0x71c7b6: file build/ALPHA_FS/mem/dramsim/mem-dram.c, line 374.
(gdb) break mem-dram.c:380
Breakpoint 2 at 0x71c7f0: file build/ALPHA_FS/mem/dramsim/mem-dram.c, line 380.
(gdb) run
one
two
f
[Switching to Thread 46985688772912 (LWP 17801)]
Breakpoint 1, set_dram_channel_width (channel_width=64)
(gdb) c
Continuing.
Breakpoint 2, set_dram_transaction_granularity (cacheline_size=64)
(gdb) c
Continuing.
Breakpoint 1, set_dram_channel_width (channel_width=8)
(gdb) c
Continuing.
afficher aussi le code externe –
...par qui Neil signifie - nous devons voir main() – slim
Vous n'avez pas donné les informations nécessaires. Plus précisément, nous ne pouvons pas voir le programme principal ou un autre code d'appel. On ne sait pas d'où vient le 'f' - c'est probablement ce que vous entrez sur le clavier, mais nous devons le savoir avec certitude. –