Re:Donut math: how donut.c works
by supportengineer on Monday September 18, 2023 @02:27AM
(#37552914)
What platform does this compile on? Didn't work for me on a recent model M1 MacBook Pro.
[ Parent
| on HN ]
Re:Donut math: how donut.c works
by physicsguy on Monday September 18, 2023 @02:39AM
(#37552991)
What were the errors?
I got it to compile in Linux on x86-64, with the following tiny changes:
- Add #include <stdio.h> (for printf())
- Add #include <string.h> (for memset())
- Add "int" before the initial bare declaration of "k"
I compiled it with:
$ gcc -o donut -std=c89 donut.c -lm
Which includes:- Specifying an old language standard to get rid of the need to say "int" before main()
- Linking the math library ("-lm") for the trig functions.
Update: minor grammar and clarification.
With -std=c89 you shouldn't need that `int k`, right?
Further, you can add includes on the command line
cc -std=c89 donut.c -include stdio.h -include string.h -include math.h -lm
Then the source can be left as is.It should compile without the #includes, possibly didplaying some compiler warnings.
Re:Donut math: how donut.c works
by forgotpwd16 on Tuesday September 19, 2023 @03:28PM
(#37575112)
Yeap. A
gcc -lm donut.c
is enough. Also type and return type default to `int` so this doesn't need change either.