Skip to content

Commit 8ce41c7

Browse files
committed
Create a dynamic library that contains C functions that can be called from Python.
1 parent f378d13 commit 8ce41c7

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
int add(int a, int b) {
2+
return a + b;
3+
}
4+
5+
int sub(int a, int b) {
6+
return a - b;
7+
}
8+
9+
int mul(int a, int b) {
10+
return a * b;
11+
}
12+
13+
int div(int a, int b) {
14+
return a / b;
15+
}
16+
17+
int mod(int a, int b) {
18+
return a % b;
19+
}
15.4 KB
Binary file not shown.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import random
2+
import ctypes
3+
4+
cops = ctypes.CDLL('./100-operations.so')
5+
a = random.randint(-111, 111)
6+
b = random.randint(-111, 111)
7+
print("{} + {} = {}".format(a, b, cops.add(a, b)))
8+
print("{} - {} = {}".format(a, b, cops.sub(a, b)))
9+
print("{} x {} = {}".format(a, b, cops.mul(a, b)))
10+
print("{} / {} = {}".format(a, b, cops.div(a, b)))
11+
print("{} % {} = {}".format(a, b, cops.mod(a, b)))

0 commit comments

Comments
 (0)