I am trying to execute the c program found here. But when I try to build it in eclipse I get numerous errors about functions being implicitly declared and registers being accessed that don’t exist. I was wondering if anybody can get this code to run and how they got it to work (program, OS, etc.) I am on a windows machine using an ubuntu virtual machine with eclipse and gcc to try and execute this code.
Here is a list of errors from Eclipse SDK (I have fixed a few bugs from the original code):
**** Build of configuration Debug for project nearpi ****
make all
Building file: ../src/nearpi.c
Invoking: GCC C Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/nearpi.d" -MT"src/nearpi.d" -o "src/nearpi.o" "../src/nearpi.c"
../src/nearpi.c:465:1: warning: return type defaults to ‘int’ [-Wreturn-type]
../src/nearpi.c: In function ‘main’:
../src/nearpi.c:501:5: warning: implicit declaration of function ‘input’ [-Wimplicit-function-declaration]
../src/nearpi.c:532:9: warning: implicit declaration of function ‘nearPiOver2’ [-Wimplicit-function-declaration]
../src/nearpi.c:540:9: warning: implicit declaration of function ‘dbleCF’ [-Wimplicit-function-declaration]
../src/nearpi.c: At top level:
../src/nearpi.c:590:1: warning: return type defaults to ‘int’ [-Wreturn-type]
../src/nearpi.c:694:1: warning: return type defaults to ‘int’ [-Wreturn-type]
../src/nearpi.c:756:1: warning: return type defaults to ‘int’ [-Wreturn-type]
../src/nearpi.c: In function ‘nearPiOver2’:
Finished building: ../src/nearpi.c
../src/nearpi.c:935:1: warning: control reaches end of non-void function [-Wreturn-type]
../src/nearpi.c: In function ‘input’:
../src/nearpi.c:748:1: warning: control reaches end of non-void function [-Wreturn-type]
Building target: nearpi
../src/nearpi.c: In function ‘main’:
Invoking: GCC C Linker
gcc -o "nearpi" ./src/nearpi.o -lm
../src/nearpi.c:564:1: warning: control reaches end of non-void function [-Wreturn-type]
Finished building target: nearpi
That code has bugs in it, when compiled on a modern compiler[*]. If I were you, I’d contact whomever licensed it, and ask for my money back.
Some of the bugs are:
#include <stdio.h>,#include <math.h>registerkeyword inccorrectly. Delete that keyword everywhere it appears.If you fix all of those bugs, it runs. I don’t know if it produces the correct answer, but it does run.
*That code was written in 1983, when the prevailing standard for C was the first edition of K&R. There have been three international standards for C published since then, and that code was never updated. Most of the bugs and warnings are a result of being very old.