Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!mcsun!ukc!acorn!osmith From: osmith@acorn.co.uk (Owen Smith) Newsgroups: comp.sys.acorn Subject: Re: Strange things in C v3 Message-ID: <5913@acorn.co.uk> Date: 19 Mar 91 14:31:53 GMT References: <7199@ecs.soton.ac.uk> Sender: osmith@acorn.co.uk Distribution: comp Organization: Acorn Computers Ltd, Cambridge, England Lines: 23 In article <7199@ecs.soton.ac.uk> rhh88@ecs.soton.ac.uk (Heywood RH) writes: >A friend of mine has discovered something a little stange with the ansi >c compiler. It seems that he could only get it to pass a float as a >function param. if he used the new ansi syntax. If he used the old >syntax it gave a compile error. Stange thing is that if he changed his >float to a double it worked. I think the reason is fairly simple. Remember the function argument type promotion rules in traditional C. Floats promote to double. Thus any functions should have their arguments declared as double not float, because by the time it gets to the function it will be a double. The compiler has probably spotted you declaring a parameter as float for a function with no prototype, and is telling you that this will not work. This is good. On other systems, you get junk parameters as the promoted argument takes 64 bits as a double but the function accesses it as 32 bits as a float. Bad news. If you have ever wondered why all the C runtime library floating point functions all take doubles as arguments, now you know. It used to be all you could pass. Function prototypes are wonderful things. Owen. The views expressed are my own and are not necessarily those of Acorn.