Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!pasteur!ames!xanth!hoptoad!tim From: tim@hoptoad.uucp (Tim Maroney) Newsgroups: comp.sys.mac.programmer Subject: Re: Stupid LightspeedC question Message-ID: <6572@hoptoad.uucp> Date: 19 Feb 89 10:19:44 GMT References: <72138CXT105@PSUVM> Reply-To: tim@hoptoad.UUCP (Tim Maroney) Organization: Eclectic Software, San Francisco Lines: 47 In article <72138CXT105@PSUVM> CXT105@PSUVM.BITNET (Christopher Tate) writes: > double deg_to_rad(x) > double x; > { > return (x*PI/180); > } > >the routine returns the same value regardless of what I pass as x. The only >way I have found to get it to work (based on the assumption that a parameter of >type double cannot be passed ordinarily, since it's 10 bytes long) is to >declare the function thus: > > double deg_to_rad(x) > double *x; > { > return ((*x)*PI/180); > } Arguments of type float are automatically converted to type double when you pass them to C functions. Arguments of type double are passed as double. If they aren't, your compiler is in error. See Kernighan and Ritchie, page 42. I may be missing something, but your functions look like they should have the same effect if both are called correctly. One thing that occurs to me is that, if deg_to_rad is in a different file from where it is called, you may have forgotten to declare it as type double before you call it. If so, then the compiler assumes it's type int, and that would seem to explain the weird behavior you're seeing. This problem would also explain your second message, which said that the above pass-by-reference form still doesn't work, and you have to pass a pointer to where the return value should go. Here's what you said did work: > void deg_to_rad(angle, x) > double *angle; > double *x; > { > *x = (*angle)*PI/180; > } Since there's no return value here, this supports the guess that the problem is in a declaration (or lack thereof) of the return value. -- Tim Maroney, Consultant, Eclectic Software, sun!hoptoad!tim "This signature is not to be quoted." -- Erland Sommarskog