Use "%lf" for doubles.

/cjw

30 juli 2023 15:34 av dayllen...@gmail.com:

> Hello everyone. So today I stumbled upon this bug when doing math
> involving conversions between float and double. A minimal example:
>
> ---
> #include <stdio.h>
>
> struct V {
>  int x, y, z;
> };
>
> struct V vec(void)
> {
>  return (struct V) { 0, 0, 1 };
> }
>
> void func(float f, struct V v)
> {
>  printf("%f %d %d %d\n", f, v.x, v.y, v.z);
> }
>
> int main(void)
> {
>  float f = 5;
>  double d = f;
>  func(d, vec());
>  return 0;
> }
> ---
>
> The code should print this:
> 5.000000 0 0 1
>
> but it prints garbage in the first value like this:
> -85964.625000 0 0 1
>
> I've tried Linux x86_64 and both mob branch and 0.9.27 release.
> tcc -run also fails.
>
> I hope there is an easy fix for this. Thanks.
>
> _______________________________________________
> 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

Reply via email to