Problem returning doubles from a function
Jin Li
jinli at gpu.utcs.toronto.edu
Sat Mar 25 04:41:56 AEST 1989
In article <39722 at csvax1.cs.tcd.ie> omahony at csvax1.cs.tcd.ie (Donal O'Mahony - OMAHONY at cs.tcd.ie) writes:
>Can anone explain the problem with the following program (made up of 2 files).
>
>::main.c
>#include <stdio.h>
>main()
>{double a,b;
>
> a = 1.234;
> b = store_length(a);
You should explicitly declare the type for 'store_length'.
ie. you do 'extern double store_length();' at the beginning.
The reason is that C assumes undeclared functions having
'int' as their type. Thus, value returned from 'store_length'
will be implicitly casted to 'int' before assigned to var 'b'.
>[deleted]...
>
>::rt1.c
>double store_length( double measurements)
>{ measurements= 2;
It is always a good idea to initialize 'double' var using
floating point representation. ie. 2.0 instead of 2
--
Jin Li >> Gin & Tonic mix well
University of Toronto Computing Services << No bugs, no bucks
jinli at gpu.utcs.utoronto.ca uunet!utgpu!jinli>> ls is a typo
More information about the Comp.lang.c
mailing list