using floats in functional prototypes
Eric Johnson
erc at pai.UUCP
Sat Jan 21 01:15:41 AEST 1989
[...]
In article <1989Jan18.092522.14499 at gpu.utcs.toronto.edu>, romwa at gpu.utcs.toronto.edu (Royal Ontario Museum) writes:
> I am having some problems with using float's in functional
> prototypes and am hoping that someone out there in netland can
> help me out. The problem seems to be isolated to float types
> and not to any other types. The examples below give the gist
> of it. Tst2.c has a function "afunc" with one parameter.
> When I compile the two files, I get a warning that the type of
> the argument in the prototype doesn't match the declaration
> (??). I experimented with this example a bit on a couple
> of compilers and each time the warnings come out. What is
> more disconcerting is that flt_val inside afunc isn't 6.5 but
> some bizarre value.
> A couple of other observations are that by changing
> the type to be double made everything work, and by removing
> the prototypes made everything work. Since MS-C 5.1, QuickC,
> and Turbo C give similar results I assume it is something
> about C that I don't understand.
> advTHANKSance
> Totally Perplexed,
>
> Pavneet Arora
> ...!utgpu!rom!pavneet
>
> Royal Ontario Museum
> 100 Queen's Park
> Toronto, Ontario
> M5S 2C6
> (416) 585-5626
I, too, had problems using a float in a function prototype for MS C 5.1.
I recently upgraded from 4.0 to 5.1 and code that worked in 4.0, using
the float in a prototype, failed in 5.1. If I remember correctly, the
5.1 compiler gave a warning message for the prototype. The fix: I removed
the prototype and everything was hunky-dory. The problem is that this
defeats the whole idea of using prototypes in the first place. It is
interesting that you state the problem appears in both Borland's and
Microsoft's compilers (we were thinking of switching to Turbo C, I
guess we won't now).
If anyone has a code section using a float in a prototype that works
under MS C 5.1, I would appreciate the example code. I may be doing
something wrong and I certainly wouldn't mind a constructive correction.
In my case, we used something like:
(I may have typed this in wrong, so no flames, please)
int foo( float /* f */, int /* i */, int /* j */ );
as the prototype
and
int
foo( f, i, j )
float f;
int i;
int j;
{
/* ... */
}
as the function. This seemed to cause great problems, as the float
value f never seemed to have the correct value upon entry to the
function. This is no fun. Again, removing the prototype seemed to
solve the problem.
Does anyone have any ideas? I would appreciate any, although dumping the
PC and getting a real computer is not really an option, no matter how
much I'd like to do that.
Thanks,
-Eric
[ Pavneet Arora's examples of the problem follow ]
>
> ---------tst.c-------------------------------------------------
> #include <stdio.h>
>
> void afunc( float );
>
> void main( void )
> {
> float flt_val = 6.5;
>
> afunc( flt_val );
> }
>
>
> ---------tst2.c------------------------------------------------
> #include <stdio.h>
>
> void afunc( float );
>
> void afunc( flt_val )
>
> float flt_val;
>
> {
> int i;
>
> i = 3;
> }
--
Eric F. Johnson | Phone +1 612-894-0313 | Are we
Prime Automation,Inc | UUCP: bungia!pai!erc | having
12201 Wood Lake Drive | UUCP: sun!tundra!pai!erc | fun
Burnsville, MN 55337 USA | DOMAIN: erc at pai.mn.org | yet?
More information about the Comp.lang.c
mailing list