Browse code

Merge pull request #184 from Icantjuddle/add_cpp_extern

Add extern "C" to headers when being compiled in c++.

John Hawthorn authored on 07/12/2024 06:19:19 • GitHub committed on 07/12/2024 06:19:19
Showing 8 changed files

... ...
@@ -3,6 +3,10 @@
3 3
 
4 4
 #include "../config.h"
5 5
 
6
+#ifdef __cplusplus 
7
+extern "C" {
8
+#endif
9
+
6 10
 #define ASSIGN_LOWER(v) \
7 11
 	['a'] = (v), \
8 12
 	['b'] = (v), \
... ...
@@ -105,4 +109,8 @@ const size_t bonus_index[256] = {
105 109
 
106 110
 #define COMPUTE_BONUS(last_ch, ch) (bonus_states[bonus_index[(unsigned char)(ch)]][(unsigned char)(last_ch)])
107 111
 
112
+#ifdef __cplusplus
113
+}
114
+#endif
115
+
108 116
 #endif
... ...
@@ -6,6 +6,10 @@
6 6
 #include "match.h"
7 7
 #include "options.h"
8 8
 
9
+#ifdef __cplusplus 
10
+extern "C" {
11
+#endif
12
+
9 13
 struct scored_result {
10 14
 	score_t score;
11 15
 	const char *str;
... ...
@@ -38,4 +42,8 @@ score_t choices_getscore(choices_t *c, size_t n);
38 42
 void choices_prev(choices_t *c);
39 43
 void choices_next(choices_t *c);
40 44
 
45
+#ifdef __cplusplus 
46
+}
47
+#endif
48
+
41 49
 #endif
... ...
@@ -1,3 +1,7 @@
1
+#ifdef __cplusplus 
2
+extern "C" {
3
+#endif
4
+
1 5
 #define TTY_COLOR_HIGHLIGHT TTY_COLOR_YELLOW
2 6
 
3 7
 #define SCORE_GAP_LEADING -0.005
... ...
@@ -17,3 +21,7 @@
17 21
 #define DEFAULT_NUM_LINES 10
18 22
 #define DEFAULT_WORKERS 0
19 23
 #define DEFAULT_SHOW_INFO 0
24
+
25
+#ifdef __cplusplus 
26
+}
27
+#endif
... ...
@@ -3,6 +3,10 @@
3 3
 
4 4
 #include <math.h>
5 5
 
6
+#ifdef __cplusplus 
7
+extern "C" {
8
+#endif
9
+
6 10
 typedef double score_t;
7 11
 #define SCORE_MAX INFINITY
8 12
 #define SCORE_MIN -INFINITY
... ...
@@ -13,4 +17,8 @@ int has_match(const char *needle, const char *haystack);
13 17
 score_t match_positions(const char *needle, const char *haystack, size_t *positions);
14 18
 score_t match(const char *needle, const char *haystack);
15 19
 
20
+#ifdef __cplusplus 
21
+}
22
+#endif
23
+
16 24
 #endif
... ...
@@ -1,6 +1,10 @@
1 1
 #ifndef OPTIONS_H
2 2
 #define OPTIONS_H OPTIONS_H
3 3
 
4
+#ifdef __cplusplus
5
+extern "C" {
6
+#endif
7
+
4 8
 typedef struct {
5 9
 	int benchmark;
6 10
 	const char *filter;
... ...
@@ -18,4 +22,8 @@ typedef struct {
18 22
 void options_init(options_t *options);
19 23
 void options_parse(options_t *options, int argc, char *argv[]);
20 24
 
25
+#ifdef __cplusplus
26
+}
27
+#endif
28
+
21 29
 #endif
... ...
@@ -1,4 +1,3 @@
1
-#include <stdio.h>
2 1
 #include <unistd.h>
3 2
 #include <fcntl.h>
4 3
 #include <stdlib.h>
... ...
@@ -1,8 +1,14 @@
1 1
 #ifndef TTY_H
2 2
 #define TTY_H TTY_H
3 3
 
4
+#include <stddef.h>
5
+#include <stdio.h>
4 6
 #include <termios.h>
5 7
 
8
+#ifdef __cplusplus 
9
+extern "C" {
10
+#endif
11
+
6 12
 typedef struct {
7 13
 	int fdin;
8 14
 	FILE *fout;
... ...
@@ -57,4 +63,8 @@ void tty_flush(tty_t *tty);
57 63
 size_t tty_getwidth(tty_t *tty);
58 64
 size_t tty_getheight(tty_t *tty);
59 65
 
66
+#ifdef __cplusplus
67
+}
68
+#endif
69
+
60 70
 #endif
... ...
@@ -5,6 +5,10 @@
5 5
 #include "options.h"
6 6
 #include "tty.h"
7 7
 
8
+#ifdef __cplusplus 
9
+extern "C" {
10
+#endif
11
+
8 12
 #define SEARCH_SIZE_MAX 4096
9 13
 
10 14
 typedef struct {
... ...
@@ -25,4 +29,8 @@ typedef struct {
25 29
 void tty_interface_init(tty_interface_t *state, tty_t *tty, choices_t *choices, options_t *options);
26 30
 int tty_interface_run(tty_interface_t *state);
27 31
 
32
+#ifdef __cplusplus
33
+}
34
+#endif
35
+
28 36
 #endif