summaryrefslogtreecommitdiffstats
path: root/Templates
diff options
context:
space:
mode:
authorDaniel Pfeifer <daniel@pfeifer-mail.de>2017-01-24 21:24:06 (GMT)
committerDaniel Pfeifer <daniel@pfeifer-mail.de>2017-01-24 21:24:06 (GMT)
commit60b68304f25088db12112c47a4599e4fef405429 (patch)
tree447be251ec72c47f030d87105230873e167dc9b7 /Templates
parent1731b90cd0b8c1c0da2f485a9b43006bb2174150 (diff)
downloadCMake-60b68304f25088db12112c47a4599e4fef405429.zip
CMake-60b68304f25088db12112c47a4599e4fef405429.tar.gz
CMake-60b68304f25088db12112c47a4599e4fef405429.tar.bz2
TestDriver: abstract CM_CAST macro
Diffstat (limited to 'Templates')
-rw-r--r--Templates/TestDriver.cxx.in22
1 files changed, 9 insertions, 13 deletions
diff --git a/Templates/TestDriver.cxx.in b/Templates/TestDriver.cxx.in
index 7d03fd3..7e17761 100644
--- a/Templates/TestDriver.cxx.in
+++ b/Templates/TestDriver.cxx.in
@@ -12,6 +12,12 @@
/* Forward declare test functions. */
@CMAKE_FORWARD_DECLARE_TESTS@
+#ifdef __cplusplus
+#define CM_CAST(TYPE, EXPR) static_cast<TYPE>(EXPR)
+#else
+#define CM_CAST(TYPE, EXPR) (TYPE)(EXPR)
+#endif
+
/* Create map. */
typedef int (*MainFuncPointer)(int, char* []);
@@ -34,13 +40,8 @@ static char* lowercase(const char* string)
char *new_string, *p;
size_t stringSize = 0;
-#ifdef __cplusplus
- stringSize = static_cast<size_t>(strlen(string) + 1);
- new_string = static_cast<char*>(malloc(sizeof(char) * stringSize));
-#else
- stringSize = (size_t)(strlen(string) + 1);
- new_string = (char*)(malloc(sizeof(char) * stringSize));
-#endif
+ stringSize = CM_CAST(size_t, strlen(string) + 1);
+ new_string = CM_CAST(char*, malloc(sizeof(char) * stringSize));
if (!new_string) {
return 0;
@@ -48,12 +49,7 @@ static char* lowercase(const char* string)
strncpy(new_string, string, stringSize);
p = new_string;
while (*p != 0) {
-#ifdef __cplusplus
- *p = static_cast<char>(tolower(*p));
-#else
- *p = (char)(tolower(*p));
-#endif
-
+ *p = CM_CAST(char, tolower(*p));
++p;
}
return new_string;