Near off topic, but on topic:
C is fake, can't be trusted and why should,
C can mess your head, if you program assembly and think C way.Let's investigate this code, pay attention to formats:
#include <stdio.h>
int main ()
{
float f;
scanf ("%f",&f);
printf("\r\n %f",f);
return 0;
}
Compiled into obj file: "gcc -g -O -c main.c" (Creates main.o)
Debug with: "objdump -D main.o >> out.txt"
Let's find entry point - main:
Disassembly of section .text:
...
...
00000000004014e0 <main>:
4014e0: 55 push %rbp
4014e1: 48 89 e5 mov %rsp,%rbp
4014e4: 48 83 ec 30 sub $0x30,%rsp
4014e8: e8 13 0e 00 00 callq 402300 <__main>
4014ed: 48 8d 45 f8 lea -0x8(%rbp),%rax
4014f1: 48 89 c2 mov %rax,%rdx
4014f4: 48 8d 0d 05 2b 00 00 lea 0x2b05(%rip),%rcx # 404000 <.rdata>
4014fb: e8 d0 15 00 00 callq 402ad0 <scanf>
401500: 48 8b 45 f8 mov -0x8(%rbp),%rax
401504: 48 89 c2 mov %rax,%rdx
401507: 66 48 0f 6e ca movq %rdx,%xmm1
40150c: 48 89 c2 mov %rax,%rdx
40150f: 48 8d 0d ee 2a 00 00 lea 0x2aee(%rip),%rcx # 404004 <.rdata+0x4>
401516: e8 bd 15 00 00 callq 402ad8 <printf>
40151b: b8 00 00 00 00 mov $0x0,%eax
401520: 48 83 c4 30 add $0x30,%rsp
401524: 5d pop %rbp
401525: c3 retq
...
There you can see is a call of scanf and printf, they load format from rdata section, so let's go, find it, those formats:
Disassembly of section .rdata:
...
...
0000000000404000 <.rdata>:
404000: 25 6c 66 00 0d and $0xd00666c,%eax
404005: 0a 20 or (%rax),%ah
404007: 25 6c 66 00 00 and $0x666c,%eax
40400c: 00 00 add %al,(%rax)
...
Here we are, line address 404000 is an address that is passed to a scanf.
So, if we passed "%f", then what is here:
404000: 25 6c 66
0x25 = ASCII '%'
0x6C = ASCII 'l'
0x66 = ASCII 'f'
results in "%lf" - long float or float64 or double.
So, where did that "L".toLowerCase() arised, if we wanted only "%f"...
1. GCC inserted "L".toLowerCase() into format.
2. GCC altered our piece of art (code) without asking us a permission.
So, well then, if something works in C and doesn't in Assembly, no wonder why.
![Smiley :)](http://forum.nasm.us/Smileys/default/smiley.gif)
No wonder my head almost hurt's from this investigation, because it was a small problem and got messy.
![Cheesy :D](http://forum.nasm.us/Smileys/default/cheesy.gif)
Well, at least, we found some answers on "why and what" was wrongy (- new word).
So, if you print code with gcc:
printf("Hello world");
Then, don't be surprised, if you debug and find into rdata section:
"<GCCWASHERE>Hello world</GCCWASHERE>"
![Cheesy :D](http://forum.nasm.us/Smileys/default/cheesy.gif)
Bye.