Checksum: 55599 Path: utzoo!utgpu!jinli From: jinli@gpu.utcs.toronto.edu (Jin Li) Date: Fri, 24-Mar-89 13:41:56 EST Message-ID: <1989Mar24.134156.11510@gpu.utcs.toronto.edu> Organization: University of Toronto Computing Services Newsgroups: comp.lang.c Subject: Re: Problem returning doubles from a function References: <39722@csvax1.cs.tcd.ie> Reply-To: jinli@gpu.utcs.UUCP (Jin Li) In article <39722@csvax1.cs.tcd.ie> omahony@csvax1.cs.tcd.ie (Donal O'Mahony - OMAHONY@cs.tcd.ie) writes: >Can anone explain the problem with the following program (made up of 2 files). > >::main.c >#include >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@gpu.utcs.utoronto.ca uunet!utgpu!jinli>> ls is a typo