summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--6p4.cpp4
-rw-r--r--Chapter6.hpp12
-rw-r--r--Makefile18
-rw-r--r--fact.cc20
-rw-r--r--factMain.cc7
6 files changed, 60 insertions, 3 deletions
diff --git a/.gitignore b/.gitignore
index c175108..3b5110b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,5 @@ bin/
redirection/
TODO
gede.ini
+*.o
+*.obj
diff --git a/6p4.cpp b/6p4.cpp
index 28c6fa5..441d423 100644
--- a/6p4.cpp
+++ b/6p4.cpp
@@ -7,7 +7,7 @@
*
*/
-uint64_t fact(void) {
+uint64_t fact_i(void) {
uint64_t val;
if(std::cin >> val) {} else { return 0; }
@@ -21,6 +21,6 @@ uint64_t fact(void) {
int main () {
- std::cout << fact() << std::endl;
+ std::cout << fact_i() << std::endl;
return 0;
}
diff --git a/Chapter6.hpp b/Chapter6.hpp
new file mode 100644
index 0000000..b3e431b
--- /dev/null
+++ b/Chapter6.hpp
@@ -0,0 +1,12 @@
+#include <iostream>
+
+/*
+ *
+ * 6.8
+ *
+ *
+ */
+
+int fact(int val);
+uint64_t fact_i(void);
+int AbsoluteValue(int v);
diff --git a/Makefile b/Makefile
index 4648bd7..259e0a6 100644
--- a/Makefile
+++ b/Makefile
@@ -8,7 +8,7 @@ OBJS_CLANG=$(patsubst %.cpp, $(BINDIR)/clang/%, $(SRCS))
OBJS_GCC=$(patsubst %.cpp, $(BINDIR)/gcc/%, $(SRCS))
MAKEFLAGS += -j$(nproc)
-all: clang gcc
+all: clang gcc ch6e9
clean:
rm -rf $(BINDIR)/gcc/*
@@ -26,4 +26,20 @@ $(BINDIR)/gcc/%: %.cpp
@mkdir -p $(BINDIR)/gcc
$(CC2) $(CFLAGS_GCC) -o $@ $<
+ch6e9: $(BINDIR)/clang/FACT $(BINDIR)/gcc/FACT
+
+$(BINDIR)/clang/FACT: fact.o factMain.o
+ @mkdir -p $(BINDIR)/clang
+ $(CC1) $(CFLAGS_CLANG) factMain.o fact.o -o $(BINDIR)/clang/FACT
+
+$(BINDIR)/gcc/FACT: fact.o factMain.o
+ @mkdir -p $(BINDIR)/gcc
+ $(CC2) $(CFLAGS_GCC) factMain.o fact.o -o $(BINDIR)/gcc/FACT
+
+fact.o: fact.cc
+ $(CC2) $(CFLAGS_GCC) -c fact.cc
+
+factMain.o: factMain.cc
+ $(CC2) $(CFLAGS_GCC) -c factMain.cc
+
.PHONY: all clean clang gcc
diff --git a/fact.cc b/fact.cc
new file mode 100644
index 0000000..a79d2b7
--- /dev/null
+++ b/fact.cc
@@ -0,0 +1,20 @@
+#include <iostream>
+
+/*
+ *
+ *
+ *
+ *
+ */
+
+uint64_t fact_i(void) {
+
+ uint64_t val;
+ if(std::cin >> val) {} else { return 0; }
+ uint64_t ret = 1;
+ while(val > 1) {
+ ret *= val--;
+ }
+
+ return ret;
+}
diff --git a/factMain.cc b/factMain.cc
new file mode 100644
index 0000000..58ae446
--- /dev/null
+++ b/factMain.cc
@@ -0,0 +1,7 @@
+#include "Chapter6.hpp"
+
+int main () {
+
+ std::cout << fact_i() << std::endl;
+ return 0;
+}