Re: GCC Differences

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Chris Rode <electro@tux.bursar.arizona.edu> writes:

[...]

> float toot(int x, float y) {
>    if (y == 20) {
>       return y;
>    } else {
>       toot(x, x*y);              (**)
>    }
> }
> 
> 
> Compiled with Red Hat's gcc 2.96, I get "nan" (however, If I take out 
> the recursive call, and just return x*y, I get 20.000000).
> 
> Compiled with Debian's 2.95.4, I get 20.000000.

If you compiled with "-Wall" you'd have seen that the line I
marked with a (**) misses a "return"; currently, the function
"toot" returns an "unspecified" value when y != 20, thus
different versions of gcc may effectively produce different
values.

Conclusion, always compile with -Wall :-).

-- 
Guillaume Cottenceau



_______________________________________________
Redhat-devel-list mailing list
Redhat-devel-list@redhat.com
https://listman.redhat.com/mailman/listinfo/redhat-devel-list

[Index of Archives]     [Kernel Newbies]     [Red Hat General]     [Fedora]     [Red Hat Install]     [Linux Kernel Development]     [Yosemite News]

  Powered by Linux