aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2013-03-19 01:10:28 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2013-03-19 01:14:06 +0100
commit274fe375264e1767a8dcaea06eaa5d6735e32e37 (patch)
tree55a799daf18cd9dff760ddaefcd6c1d413c8c26f
parent735b4c4b743a774c5d53ab6a8e10f0f8308a925b (diff)
downloadsciteco-274fe375264e1767a8dcaea06eaa5d6735e32e37.tar.gz
rewritten CHR2STR() using compound statement
* fixes compilation on g++ 4.7 where compound literals are suddenly temporaries (from which you cannot get a pointer) * the compound statement (also GCC extension) should ensure that the string is allocated on the stack with automatic lifetime
-rw-r--r--src/parser.cpp4
-rw-r--r--src/sciteco.h7
2 files changed, 8 insertions, 3 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index cb1f577..66880e3 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -322,7 +322,7 @@ StateCtlE:
break;
default:
set(StateStart);
- return g_strdup((gchar []){CTL_KEY('E'), chr, '\0'});
+ return g_strdup(CHR2STR(CTL_KEY('E'), chr));
}
return NULL;
@@ -343,7 +343,7 @@ StateCtlEU:
undo.push_obj(qregspec_machine) = NULL;
set(StateStart);
- return g_strdup(CHR2STR(reg->get_integer()));
+ return g_strdup(CHR2STR((gchar)reg->get_integer()));
StateCtlEQ:
reg = qregspec_machine->input(chr);
diff --git a/src/sciteco.h b/src/sciteco.h
index 84c9775..a1e2d4b 100644
--- a/src/sciteco.h
+++ b/src/sciteco.h
@@ -63,7 +63,12 @@ extern sig_atomic_t sigint_occurred;
#define IS_SUCCESS(X) ((X) < 0)
#define IS_FAILURE(X) (!IS_SUCCESS(X))
-#define CHR2STR(X) ((gchar []){X, '\0'})
+/*
+ * NOTE: compound literals are temporaries beginning with
+ * g++ 4.7
+ */
+#define CHR2STR(X, ...) \
+ ({gchar str[] = {(X), ##__VA_ARGS__, '\0'}; str;})
namespace String {