Re: sqrt C function(clarification)
> I'm sorry not to have provided more information in my first e-mail although
> i'm very glad so many people responded to help, but i've done some more
> testing:
>
> specifically i'm getting 'prase error in tmp/x' where x is a long string of
> characters that tends to change on every run of the complier (at least when
> i'm compiling other programs). I've tried the following and gotten no errors
>
> #include <stdio.h>
> #include <math.h>
>
> double num=16.0;
>
> int main()
> {
> double sqrt(double num);
> return(0);
> }
>
> the following warns me that 'function sqrt does not match global variable'
> but still compiles
>
> #include <stdio.h>
> #include <math.h>
>
> float num;
>
> int main()
> {
> float sqrt(float num);
> return(0);
> }
>
> and this one just doesn't work at all giving the parse error previously
> described:
>
> #include <stdio.h>
> #include <math.h>
>
> double num;
>
> int main()
> {
> num = 16; /*i've also tried 16. and 16.0 here*/
> double sqrt(double num);
> return(0);
> }
>
[12:13:02 tmp]$ cat sqrt.c
#include <stdio.h>
#include <math.h>
double num;
int main()
{
num = 16; /*i've also tried 16. and 16.0 here*/
double sqrt(double num);
return(0);
}
[12:13:10 tmp]$ gcc -Wall sqrt.c -o sqrt -lm
sqrt.c: In function `main':
sqrt.c:9: parse error before `double'
[12:13:25 tmp]$ gcc -v
Reading specs from /usr/lib/gcc-lib/i386-linux/2.95.4/specs
gcc version 2.95.4 20010319 (Debian prerelease)
[12:21:32 tmp]$
You can not have a deceleration (double sqrt(double);) after a command (num =
16;) in the same block. Replacing the order of
num = 16
and
double sqrt(double num);
fixed the warning for me. I can not reproduce the tmp/x error you are
reporting. Maybe you should try to type the whole file from scratch, possibly
in another dir?
> I'm sorry I was not more clear with my first e-mail and hope this points out
> the problem better. Also, how do I let gcc know that I want math.h to be an
> available library so i dont' have to use the -l option every time if run it?
>
Do not know the answer for getting -lm by default. You might try info gcc.
This will not be an issue with larger projects since one would use make:
[12:29:37 tmp]$ cat Makefile
CFLAGS = -Wall
LDFLAGS = -lm
sqrt: sqrt.c
cc -o $@ $< $(CFLAGS) $(LDFLAGS)
[12:29:39 tmp]$ make
cc -o sqrt sqrt.c -Wall -lm
[12:29:46 tmp]$
> one final thing: did any of you try comiling the non-working examples on your
> gcc's? did you get any errors?
>
> thanks a lot
>
>
> --
> To UNSUBSCRIBE, email to debian-user-request@lists.debian.org
> with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
>
--
Shaul Karl <shaulka@bezeqint.net>
Reply to: