E
elzacho
It is my understanding that prototypes in C are purely optional. To my
experience, until today I guess, this has been the case (other than
eliminating compiler warning messages).
However, today I wrote a routine to search an array for values greater
than a certain limiting value (double) and something weird happened.
When debuging I noticed that I passed the limiting value to the routine
yet inside the function this value was garbage. This was very odd to
me and the value was something like 10^-315 for this double so it
looked like it was maybe an integer value which I thought was a double.
Thinking that there was some kind of type casting going on behind the
scenes, I added the prototype and the problem went away.
So, am I wrong and prototypes are mandatory, kinda like in C++? Does
the compiler automatically assume that unknown functions have only
integer arguments and thus puts in a type cast for me? This wouldn't
affect pointers or int, long, chars but only floats and doubles which
is kinda what I am seeing.
I am using gcc 3.3.4 if that makes a difference.
Thanks,
Zach
experience, until today I guess, this has been the case (other than
eliminating compiler warning messages).
However, today I wrote a routine to search an array for values greater
than a certain limiting value (double) and something weird happened.
When debuging I noticed that I passed the limiting value to the routine
yet inside the function this value was garbage. This was very odd to
me and the value was something like 10^-315 for this double so it
looked like it was maybe an integer value which I thought was a double.
Thinking that there was some kind of type casting going on behind the
scenes, I added the prototype and the problem went away.
So, am I wrong and prototypes are mandatory, kinda like in C++? Does
the compiler automatically assume that unknown functions have only
integer arguments and thus puts in a type cast for me? This wouldn't
affect pointers or int, long, chars but only floats and doubles which
is kinda what I am seeing.
I am using gcc 3.3.4 if that makes a difference.
Thanks,
Zach