• R/O
  • SSH

libctools: Commit

This library contains code that extends and simplifies different operations
for C language based programs.


Commit MetaInfo

Revisión5ab5f6fd4751ee0364450d191b1b9e7a951ec117 (tree)
Tiempo2017-01-30 07:49:48
Autors.gusarov
Commiters.gusarov

Log Message

Module minmax renamed to min_max

Cambiar Resumen

Diferencia incremental

diff -r 12be7c9184e5 -r 5ab5f6fd4751 include/ctools/min_max.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/include/ctools/min_max.h Mon Jan 30 01:49:48 2017 +0300
@@ -0,0 +1,67 @@
1+/*
2+ * @author Sergey Gusarov <laborer2008 (at) gmail.com>
3+ * @section LICENSE
4+ * This Source Code Form is subject to the terms of the Mozilla Public
5+ * License, v. 2.0. If a copy of the MPL was not distributed with this
6+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7+ *
8+ * @section DESCRIPTION
9+ * Calculation of minimum/maximum value from 2 arguments.
10+ * See http://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax
11+ * for jumpless macros. But it seems that modern compilers can do it:
12+ * http://stackoverflow.com/a/7475388
13+ * So we shouldn't care
14+ */
15+
16+#pragma once
17+
18+#include "ctools/predef/compiler.h"
19+
20+
21+#ifdef CT_MAX2
22+# error CT_MAX2 must be undefined
23+#endif
24+
25+#ifdef CT_MIN2
26+# error CT_MIN2 must be undefined
27+#endif
28+
29+
30+#if defined (CT_COMPL_GCC_EMULATION) && !defined (CT_COMPL_ARMCC)
31+
32+/*
33+ * See:
34+ * https://gcc.gnu.org/onlinedocs/gcc/Typeof.html
35+ * https://gcc.gnu.org/onlinedocs/cpp/Duplication-of-Side-Effects.html
36+ */
37+
38+# ifdef _a
39+# error _a must be undefined
40+# endif
41+
42+# ifdef _b
43+# error _b must be undefined
44+# endif
45+
46+/* *INDENT-OFF* */
47+# define CT_MAX2(a, b)\
48+ ({\
49+ __typeof__(a) _a = (a);\
50+ __typeof__(b) _b = (b);\
51+ _a >= _b ? _a : _b;\
52+ })
53+
54+# define CT_MIN2(a, b)\
55+ ({\
56+ __typeof__(a) _a = (a);\
57+ __typeof__(b) _b = (b);\
58+ _a < _b ? _a : _b;\
59+ })
60+/* *INDENT-ON* */
61+
62+#else
63+
64+# define CT_MAX2(a, b) ((a) >= (b) ? (a) : (b))
65+# define CT_MIN2(a, b) ((a) < (b) ? (a) : (b))
66+
67+#endif // defined (CT_COMPL_GCC_EMULATION)
diff -r 12be7c9184e5 -r 5ab5f6fd4751 include/ctools/minmax.h
--- a/include/ctools/minmax.h Sun Jan 29 23:09:13 2017 +0300
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,67 +0,0 @@
1-/*
2- * @author Sergey Gusarov <laborer2008 (at) gmail.com>
3- * @section LICENSE
4- * This Source Code Form is subject to the terms of the Mozilla Public
5- * License, v. 2.0. If a copy of the MPL was not distributed with this
6- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7- *
8- * @section DESCRIPTION
9- * Calculation of minimum/maximum value from 2 arguments.
10- * See http://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax
11- * for jumpless macros. But it seems that modern compilers can do it:
12- * http://stackoverflow.com/a/7475388
13- * So we shouldn't care
14- */
15-
16-#pragma once
17-
18-#include "ctools/predef/compiler.h"
19-
20-
21-#ifdef CT_MAX2
22-# error CT_MAX2 must be undefined
23-#endif
24-
25-#ifdef CT_MIN2
26-# error CT_MIN2 must be undefined
27-#endif
28-
29-
30-#if defined (CT_COMPL_GCC_EMULATION) && !defined (CT_COMPL_ARMCC)
31-
32-/*
33- * See:
34- * https://gcc.gnu.org/onlinedocs/gcc/Typeof.html
35- * https://gcc.gnu.org/onlinedocs/cpp/Duplication-of-Side-Effects.html
36- */
37-
38-# ifdef _a
39-# error _a must be undefined
40-# endif
41-
42-# ifdef _b
43-# error _b must be undefined
44-# endif
45-
46-/* *INDENT-OFF* */
47-# define CT_MAX2(a, b)\
48- ({\
49- __typeof__(a) _a = (a);\
50- __typeof__(b) _b = (b);\
51- _a >= _b ? _a : _b;\
52- })
53-
54-# define CT_MIN2(a, b)\
55- ({\
56- __typeof__(a) _a = (a);\
57- __typeof__(b) _b = (b);\
58- _a < _b ? _a : _b;\
59- })
60-/* *INDENT-ON* */
61-
62-#else
63-
64-# define CT_MAX2(a, b) ((a) >= (b) ? (a) : (b))
65-# define CT_MIN2(a, b) ((a) < (b) ? (a) : (b))
66-
67-#endif // defined (CT_COMPL_GCC_EMULATION)
diff -r 12be7c9184e5 -r 5ab5f6fd4751 src/std/string.c
--- a/src/std/string.c Sun Jan 29 23:09:13 2017 +0300
+++ b/src/std/string.c Mon Jan 30 01:49:48 2017 +0300
@@ -31,7 +31,7 @@
3131 # include <stdlib.h>
3232 CT_END_EXTERNAL_HEADERS
3333
34-#include "ctools/minmax.h"
34+#include "ctools/min_max.h"
3535 #include "ctools/pointer.h"
3636 #include "ctools/trace.h"
3737
diff -r 12be7c9184e5 -r 5ab5f6fd4751 tests/src/test_min_max.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/src/test_min_max.c Mon Jan 30 01:49:48 2017 +0300
@@ -0,0 +1,40 @@
1+/*
2+ * @author Sergey Gusarov <laborer2008 (at) gmail.com>
3+ * @section LICENSE
4+ * This Source Code Form is subject to the terms of the Mozilla Public
5+ * License, v. 2.0. If a copy of the MPL was not distributed with this
6+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7+ *
8+ * @section DESCRIPTION
9+ *
10+ */
11+
12+#include "tests/unity_headers.h"
13+
14+#include <ctools/min_max.h>
15+
16+
17+void setUp(void)
18+{
19+}
20+
21+void tearDown(void)
22+{
23+}
24+
25+static const int a = -10;
26+static const int b = 3;
27+
28+void testMin(void)
29+{
30+ const int c = CT_MIN2(a, b);
31+
32+ TEST_ASSERT_EQUAL_INT(c, a);
33+}
34+
35+void testMax(void)
36+{
37+ const int d = CT_MAX2(a, b);
38+
39+ TEST_ASSERT_EQUAL_INT(d, b);
40+}
diff -r 12be7c9184e5 -r 5ab5f6fd4751 tests/src/test_minmax.c
--- a/tests/src/test_minmax.c Sun Jan 29 23:09:13 2017 +0300
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
1-/*
2- * @author Sergey Gusarov <laborer2008 (at) gmail.com>
3- * @section LICENSE
4- * This Source Code Form is subject to the terms of the Mozilla Public
5- * License, v. 2.0. If a copy of the MPL was not distributed with this
6- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7- *
8- * @section DESCRIPTION
9- *
10- */
11-
12-#include "tests/unity_headers.h"
13-
14-#include <ctools/minmax.h>
15-
16-
17-void setUp(void)
18-{
19-}
20-
21-void tearDown(void)
22-{
23-}
24-
25-static const int a = -10;
26-static const int b = 3;
27-
28-void testMin(void)
29-{
30- const int c = CT_MIN2(a, b);
31-
32- TEST_ASSERT_EQUAL_INT(c, a);
33-}
34-
35-void testMax(void)
36-{
37- const int d = CT_MAX2(a, b);
38-
39- TEST_ASSERT_EQUAL_INT(d, b);
40-}
Show on old repository browser