On Wed, Dec 24, 2014 at 8:53 PM, Daniel Glöckner <daniel...@gmx.net> wrote: > > The return value of a function returning an int is not passed in the > register where a double would be returned, so you might get garbage > that is in no way related to the input.
You are correct. Assembly code generated by tcc reveals the difference caused by the properly prototype of `sin'. For example, on x86-64, int type return value will be in rax, but double type return value in xmm0. Without properly prototype of `sin', tcc will 1. read return value from rax instead of xmm0 after sin call 2. pass the second argument of printf in rdi instead of xmm0 This is all wrong... > > On top of that the int is not cast to double in > printf("\n%f", sin(1.0)); > The bytes on the stack are simply reinterpreted as double, so > printf("%f\n", 1); > will not print 1.000000. That's because of the ellipsis in the > declaration of printf. Exactly. lee > > Best regards, > > Daniel > > _______________________________________________ > Tinycc-devel mailing list > Tinycc-devel@nongnu.org > https://lists.nongnu.org/mailman/listinfo/tinycc-devel _______________________________________________ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel