This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
what's wrong with it?
- From: Zhiyong Xu <rodgexu at yahoo dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Fri, 23 Mar 2007 09:53:07 -0700 (PDT)
- Subject: what's wrong with it?
t.c
/*
* Evaluate a function at three points, displaying
results.
*/
void
evaluate(double f(double f_arg), double pt1, double
pt2, double pt3)
{
printf("f(%.5f) = %.5f\n", pt1, f(pt1));
printf("f(%.5f) = %.5f\n", pt2, f(pt2));
printf("f(%.5f) = %.5f\n", pt3, f(pt3));
}
compile:
$gcc -lm ex.c t.c
$./a.out
f(2.00000) = 0.90930
f(3.00000) = 0.14112
f(4.00000) = -0.75680
f(2.00000) = 1.41421
f(3.00000) = 1.73205
f(4.00000) = 2.00000
if change ex.c, add the prototype of function evaluate
ex.c
#include <stdio.h>
#include <math.h>
void
evaluate(double f(double f_arg), double pt1, double
pt2, double pt3);
int main(void)
{
evaluate(sin, 2,3,4);
evaluate(sqrt,2,3,4);
return(0);
}
compile:
$gcc -lm ex.c t.c
$./a.out
f(2.00000) = 0.90930
f(3.00000) = 0.14112
f(4.00000) = -0.75680
f(2.00000) = 1.41421
f(3.00000) = 1.73205
f(4.00000) = 2.00000
here's the description:
1. I have a function evaluate defined in t.c
2. in ex.c, I call function evaluate without prototype
defined.
using gcc -lm ex.c t.c, I can generate the executable
file a.out,
when executing, the result is wrong
3. if I modify ex.c, add the prototype definition, the
result is correct.
Anything wrong with the first case?
____________________________________________________________________________________
8:00? 8:25? 8:40? Find a flick in no time
with the Yahoo! Search movie showtime shortcut.
http://tools.search.yahoo.com/shortcuts/#news