Public domain
#include <stdio.h>
#include "reciprocal.hpp"
int main (int argc, char **argv)
{
int i;
i = atoi (argv[1]);
printf ("The reciprocal of %d is %g \n", i, reciprocal(i));
return 0;
}
#include <cassert>
#include "reciprocal.hpp"
double reciprocal (int i) {
// i should be none zero
assert (i!=0);
return 1.0/i;
}
#ifdef __cplusplus
extern "C" {
#endif
extern double reciprocal (int i);
#ifdef __cplusplus
}
#endif
gcc -c main.c
g++ -c reciprocal.cpp
g++ -o reciprocal main.o reciprocal.o
reciprocal: main.o reciprocal.o
g++ $(CFLAGS) -o reciprocal main.o reciprocal.o
main.o: main.c reciprocal.hpp
gcc $(CFLAGS) -c main.c
reciprocal.o: reciprocal.cpp reciprocal.hpp
g++ $(CFLAGS) -c reciprocal.cpp
clean:
rm -f *.o reciprocal
make
make clean
make CFLAGS=-O2
make clean
make CFLAGS=-g
BY: Pejman Moghadam
TAG: c, cpp, make
DATE: 2011-05-28 14:50:39