Xref: utzoo comp.lang.c:15661 comp.sys.ibm.pc:23505 Path: utzoo!attcan!uunet!lll-winken!ncis.llnl.gov!helios.ee.lbl.gov!nosc!ucsd!rutgers!rochester!pt.cs.cmu.edu!b.gp.cs.cmu.edu!Ralf.Brown@B.GP.CS.CMU.EDU From: Ralf.Brown@B.GP.CS.CMU.EDU Newsgroups: comp.lang.c,comp.sys.ibm.pc Subject: Re: using floats in functional prototypes Summary: mixing old and new-style declarations Message-ID: <23d5d581@ralf> Date: 19 Jan 89 12:33:05 GMT Sender: ralf@b.gp.cs.cmu.edu Lines: 38 In-Reply-To: <1989Jan18.092522.14499@gpu.utcs.toronto.edu> In article <1989Jan18.092522.14499@gpu.utcs.toronto.edu>, romwa@gpu.utcs.toronto.edu (Royal Ontario Museum) writes: }I am having some problems with using float's in functional }prototypes ... }When I compile the two files, I get a warning that the type of }the argument in the prototype doesn't match the declaration }---------tst2.c------------------------------------------------ }#include } }void afunc( float ); } }void afunc( flt_val ) } }float flt_val; } }{ } int i; } } i = 3; }} } The problem is that you are using an old-style declaration. In old-style declarations, parameters get widened according to specific rules. One of the rules is that floats get widened to double, so you are really declaring a function that takes a double parameter. That's why the compilers complain, and also why you get garbage for the parameter--it is taking the four bytes for the float plus an additional four bytes of garbage from the stack and trying to interpret that as a double. If you're going to use prototypes, you're pretty much going to have to use new-style declarations when defining functions. (i.e. void afunc(float flt_val) ) -- UUCP: {ucbvax,harvard}!cs.cmu.edu!ralf -=-=-=- Voice: (412) 268-3053 (school) ARPA: ralf@cs.cmu.edu BIT: ralf%cs.cmu.edu@CMUCCVMA FIDO: Ralf Brown 1:129/31 Disclaimer? I claimed something? You cannot achieve the impossible without attempting the absurd.