summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build/top.mk2
-rw-r--r--ucoo/common.hh11
-rw-r--r--ucoo/hal/uart/test/test_uart.cc2
-rw-r--r--ucoo/utils/test/test_crc.cc2
4 files changed, 11 insertions, 6 deletions
diff --git a/build/top.mk b/build/top.mk
index 4de2438..385df77 100644
--- a/build/top.mk
+++ b/build/top.mk
@@ -18,7 +18,7 @@ CPPFLAGS := $(DEFS) $(INCLUDES) -MP -MMD
OPTIMIZE ?= -Os
CFLAGS := -g -Wall -W -Wundef -Wno-unused-parameter \
-fno-exceptions $(OPTIMIZE)
-CXXFLAGS := $(CFLAGS) -fno-rtti -fno-threadsafe-statics
+CXXFLAGS := $(CFLAGS) -fno-rtti -fno-threadsafe-statics -std=gnu++11 -Wno-deprecated-declarations
LDFLAGS :=
LDLIBS := $(LIBS)
diff --git a/ucoo/common.hh b/ucoo/common.hh
index 282041f..505cf60 100644
--- a/ucoo/common.hh
+++ b/ucoo/common.hh
@@ -83,9 +83,14 @@ assert_perror (bool condition)
halt_perror ();
}
-} // namespace ucoo
+/// Get array length at compile time.
+template<class T, int N>
+constexpr int
+lengthof (T (&)[N])
+{
+ return N;
+}
-/// Get array length at compile time, must be a macro until c++11.
-#define lengthof(array) (sizeof (array) / sizeof((array)[0]))
+} // namespace ucoo
#endif // ucoo_common_h
diff --git a/ucoo/hal/uart/test/test_uart.cc b/ucoo/hal/uart/test/test_uart.cc
index c1b111c..2c326f3 100644
--- a/ucoo/hal/uart/test/test_uart.cc
+++ b/ucoo/hal/uart/test/test_uart.cc
@@ -56,7 +56,7 @@ main (int argc, const char **argv)
char buf[64];
while (1)
{
- for (int i = 0; i < (int) lengthof (u); i++)
+ for (int i = 0; i < (int) ucoo::lengthof (u); i++)
{
if (u[i]->poll ())
{
diff --git a/ucoo/utils/test/test_crc.cc b/ucoo/utils/test/test_crc.cc
index c20600d..219c38b 100644
--- a/ucoo/utils/test/test_crc.cc
+++ b/ucoo/utils/test/test_crc.cc
@@ -35,7 +35,7 @@ main (int argc, const char **argv)
{
ucoo::Test test (tsuite, "crc8 test vector");
static const uint8_t test_vector[] = { 0x02, 0x1c, 0xb8, 0x01, 0, 0, 0, 0xa2 };
- if (ucoo::crc8_compute (test_vector, lengthof (test_vector)) != 0)
+ if (ucoo::crc8_compute (test_vector, ucoo::lengthof (test_vector)) != 0)
test.fail ();
}
{