aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2016-10-07 22:06:29 +0200
committertomsmeding <tom.smeding@gmail.com>2016-10-07 22:06:29 +0200
commit70a7537584889cf612ddea83eb65fd42818f6e5e (patch)
tree7d84990995b5d3163b193078058736a46d62b089
parent241518f369efce64046be36a15fcb722b00e9477 (diff)
Make code work on Linux and older compilers
-rw-r--r--Makefile8
-rw-r--r--bigint.cpp2
-rw-r--r--bigint.h8
-rw-r--r--main.cpp3
-rw-r--r--rng.cpp6
5 files changed, 19 insertions, 8 deletions
diff --git a/Makefile b/Makefile
index 14220de..5778290 100644
--- a/Makefile
+++ b/Makefile
@@ -1,10 +1,14 @@
CXX = g++
-CXXFLAGS = -Wall -Wextra -std=c++11 -fwrapv
+CXXFLAGS = -Wall -Wextra -std=c++0x -fwrapv
+LDFLAGS =
ifneq ($(DEBUG),)
CXXFLAGS += -g
else
CXXFLAGS += -O2
endif
+ifeq ($(shell uname),Linux)
+ LDFLAGS += -lbsd
+endif
BIN = main
.PHONY: all clean remake
@@ -18,7 +22,7 @@ remake: clean all
$(BIN): $(patsubst %.cpp,%.o,$(wildcard *.cpp))
- $(CXX) -o $@ $^
+ $(CXX) -o $@ $^ $(LDFLAGS)
%.o: %.cpp $(wildcard *.h)
$(CXX) $(CXXFLAGS) -c -o $@ $<
diff --git a/bigint.cpp b/bigint.cpp
index 1f71cf9..98846e0 100644
--- a/bigint.cpp
+++ b/bigint.cpp
@@ -617,7 +617,7 @@ std::ostream& operator<<(std::ostream &os,Bigint b){
return os;
#else
if(b==0)return os<<'0';
- Bigint div(1000000000000000000LL);
+ Bigint div((int64_t)1000000000000000000LL);
vector<Bigint::longdigit_t> outbuf;
while(b!=0){
pair<Bigint,Bigint> dm=b.divmod(div);
diff --git a/bigint.h b/bigint.h
index 24f0945..bd15fd9 100644
--- a/bigint.h
+++ b/bigint.h
@@ -8,10 +8,10 @@
class Bigint{
public:
- using digit_t=uint32_t;
- using sdigit_t=int32_t;
- using longdigit_t=uint64_t;
- using slongdigit_t=int64_t;
+ typedef uint32_t digit_t;
+ typedef int32_t sdigit_t;
+ typedef uint64_t longdigit_t;
+ typedef int64_t slongdigit_t;
static const int digit_bits=8*sizeof(digit_t);
private:
diff --git a/main.cpp b/main.cpp
index 2cd31ec..0481f6c 100644
--- a/main.cpp
+++ b/main.cpp
@@ -2,6 +2,7 @@
#include <fstream>
#include <sstream>
#include <stdexcept>
+#include <algorithm>
#include <cstdlib>
#include <cctype>
#include <ctime>
@@ -133,7 +134,7 @@ void testisqrt(int argc,char **argv){
void performrsa(){
RSA::PrivateKey privkey;
Bigint p(1000000007),q(3000000019U);
- privkey.pub.mod=3000000040000000133LL;
+ privkey.pub.mod=(int64_t)3000000040000000133LL;
privkey.pub.exp=65537;
{
Bigint x;
diff --git a/rng.cpp b/rng.cpp
index aba1c02..a6c61f5 100644
--- a/rng.cpp
+++ b/rng.cpp
@@ -4,6 +4,12 @@
#include <cassert>
#include "rng.h"
+#ifdef __APPLE__
+#include <cstdlib>
+#else
+#include <bsd/stdlib.h>
+#endif
+
using namespace std;