diff --git a/common/memory.c b/common/memory.c
index b84a20824ed23f61c747cfe3471f98ac627f4969..b8cdf42b320bfc206ff65314f3145c1851a7a50a 100644
--- a/common/memory.c
+++ b/common/memory.c
@@ -503,7 +503,9 @@ void Free(void *ptr)
     }
 }
 
+#ifdef MEMORY_DEBUG
 static const size_t maxprint = 32;
+#endif
 
 void check_mem_leak(const char *program_name)
 {
diff --git a/common/usage_stats.cc b/common/usage_stats.cc
index 74bc47c907d7651e6ef08fa69d3c54ce6f6ae09c..4eb264a361e3efa8573e0344a01de13ac2dd27da 100644
--- a/common/usage_stats.cc
+++ b/common/usage_stats.cc
@@ -117,7 +117,7 @@ std::string gethostnameFullyQualified ( void )
     }
 
     if( !domain[0] && NULL != (fp=fopen("/etc/defaultdomain","r")) ) {
-      fgets(domain, sizeof(domain), fp);
+      (void)fgets(domain, sizeof(domain), fp);
       fclose(fp);
     }
 
@@ -238,7 +238,7 @@ ssize_t process_http(int sockfd, const char *host, const char *page, const char
      "Content-length: %lu\r\n\r\n"
      "%s", page, host, (unsigned long)strlen(poststr), poststr);
 
-  write(sockfd, sendline, strlen(sendline));
+  (void)write(sockfd, sendline, strlen(sendline));
   /*while ((n = read(sockfd, recvline, MAXLINE)) > 0) {
     recvline[n] = '\0';
     printf("%s", recvline);
diff --git a/compiler2/AST.cc b/compiler2/AST.cc
index 4c74e61dd1d7f987bdd819e16f393d3eb57b25e8..82686289f829e85b3b30aefd6995e1015ae5ff5d 100644
--- a/compiler2/AST.cc
+++ b/compiler2/AST.cc
@@ -1037,19 +1037,19 @@ namespace Common {
     // All we can do is store NULLs for the unused namespaces.
     size_t num_xml_namespaces = namespaces.size();
     if (moduletype == MOD_TTCN) { //TODO remove this when ASN.1 gets EXER
-      output->source.global_vars = mputprintf(output->source.global_vars,
 #ifndef NDEBUG
+      output->source.global_vars = mputprintf(output->source.global_vars,
         "// written by %s in " __FILE__ " at %d\n"
-#endif
-        "static const size_t num_namespaces = %lu;\n"
-#ifndef NDEBUG
         , __FUNCTION__, __LINE__
-#endif
-        , (unsigned long)num_xml_namespaces
       );
+#endif
+
       if (num_xml_namespaces != 0 || (control_ns && control_ns_prefix)) {
-        output->source.global_vars = mputstr(output->source.global_vars,
-          "static const namespace_t xml_namespaces[num_namespaces+1] = {\n");
+        output->source.global_vars = mputprintf(output->source.global_vars,
+          "static const size_t num_namespaces = %lu;\n"
+          "static const namespace_t xml_namespaces[num_namespaces+1] = {\n"
+          , (unsigned long)num_xml_namespaces
+        );
         for (size_t i=0; i < namespaces.size(); ++i) {
           if (used_namespaces.has_key(i)) {
             output->source.global_vars = mputprintf(output->source.global_vars,
diff --git a/compiler2/PredefFunc.cc b/compiler2/PredefFunc.cc
index 8252f49a2c2266617d2c8a82477d439c7b70d2c8..2a36c8877af3bc6c47c4acfd0a01ab20aae21442 100644
--- a/compiler2/PredefFunc.cc
+++ b/compiler2/PredefFunc.cc
@@ -751,7 +751,7 @@ string* remove_bom(const string& encoded_value)
 {
   size_t length = encoded_value.size();
   if (0 == length) return new string();
-  if (length % 2 || 0 > length) {
+  if (length % 2) {
     ERROR("remove_bom(): Wrong string. The number of nibbles (%d) in string "
                 "shall be divisible by 2", static_cast<int>(length));
     return new string(encoded_value);
@@ -819,7 +819,7 @@ string* get_stringencoding(const string& encoded_value)
 {
   size_t length = encoded_value.size();
   if (0 == length) return new string("<unknown>");
-  if (length % 2 || 0 > length) {
+  if (length % 2) {
     ERROR("get_stringencoding(): Wrong string. The number of nibbles (%d) in string "
                 "shall be divisible by 2", static_cast<int>(length));
     return new string("<unknown>");
diff --git a/compiler2/Type_codegen.cc b/compiler2/Type_codegen.cc
index 674e133721f5da0cf8e1de498fc6f2861063a5fa..f6225b8938ae4008a5f3a280742d673a8607ded2 100644
--- a/compiler2/Type_codegen.cc
+++ b/compiler2/Type_codegen.cc
@@ -3037,7 +3037,7 @@ void Type::generate_json_schema_array(JSON_Tokenizer& json)
       "\"record of\"" : "\"set of\"");
   } else {
     // set the number of elements for arrays
-    char* size_str = mprintf("%lu", get_nof_comps());
+    char* size_str = mprintf("%lu", (unsigned long)(get_nof_comps()));
     json.put_next_token(JSON_TOKEN_NAME, "minItems");
     json.put_next_token(JSON_TOKEN_NUMBER, size_str);
     json.put_next_token(JSON_TOKEN_NAME, "maxItems");
diff --git a/compiler2/ttcn3/compiler.y b/compiler2/ttcn3/compiler.y
index 66ef6511efbbb112da8f97cb6506bb079cf7f9d8..baf1a8e339337b6360f8ea0efd77427fc3f37066 100644
--- a/compiler2/ttcn3/compiler.y
+++ b/compiler2/ttcn3/compiler.y
@@ -8747,7 +8747,7 @@ PredefinedOps:
     if ($3->get_nof_logargs() != 1) {
       Location loc(infile, @1);
       loc.error("The any2unistr function takes exactly one argument, not %lu.",
-        $3->get_nof_logargs());
+        (unsigned long)($3->get_nof_logargs()));
         delete $3;
         $$ = new Value(Value::OPTYPE_ANY2UNISTR, new LogArguments());
         $$->set_location(infile, @$);
diff --git a/core/ProfilerTools.cc b/core/ProfilerTools.cc
index cf70300eacee500a2062e1eccbaf332a65e96966..b5c9db6deb7cdee2f87bbc0adb3b99247e74aac0 100644
--- a/core/ProfilerTools.cc
+++ b/core/ProfilerTools.cc
@@ -897,7 +897,7 @@ namespace Profiler_Tools {
       // number of lines and functions
       if (p_flags & STATS_NUMBER_OF_LINES) {
         line_func_count_str = mputprintf(line_func_count_str, "%s:\t%lu lines,\t%lu functions\n",
-           p_db[i].filename, p_db[i].lines.size(), p_db[i].functions.size());
+           p_db[i].filename, (unsigned long)(p_db[i].lines.size()), (unsigned long)(p_db[i].functions.size()));
       }
       total_code_lines += p_db[i].lines.size();
       total_functions += p_db[i].functions.size();
@@ -905,7 +905,7 @@ namespace Profiler_Tools {
     if (p_flags & STATS_NUMBER_OF_LINES) {
       line_func_count_str = mputprintf(line_func_count_str,
         "--------------------------------------\n"
-        "Total:\t%lu lines,\t%lu functions\n", total_code_lines, total_functions);
+        "Total:\t%lu lines,\t%lu functions\n", (unsigned long)total_code_lines, (unsigned long)total_functions);
     }
 
     if (p_flags & (STATS_TOP10_ALL_DATA | STATS_ALL_DATA_SORTED)) {
diff --git a/core/Runtime.cc b/core/Runtime.cc
index 44c4ce1786678f61e9b7178281d9dfc40245443e..fd4423e6a8b00ff206f17c0385f5a0d8fd89e53e 100644
--- a/core/Runtime.cc
+++ b/core/Runtime.cc
@@ -2895,7 +2895,7 @@ void TTCN_Runtime::wait_terminated_processes()
   errno = 0;
   for ( ; ; ) {
     int statuscode;
-    struct rusage r_usage = {{0,0},{0,0},0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+    struct rusage r_usage = {{0,0},{0,0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0}};
 #ifdef INTERIX
     pid_t child_pid = waitpid(-1, &statuscode, WNOHANG);
     getrusage(RUSAGE_CHILDREN, &r_usage);
diff --git a/core/XER.hh b/core/XER.hh
index 80d220cf081718dca851a14d7fafe01878cfe7a4..efc41a4afeff486793f48cb2f1a0a817d207a67f 100644
--- a/core/XER.hh
+++ b/core/XER.hh
@@ -25,7 +25,7 @@ class XmlReaderWrap;
 class Base_Type;
 #ifdef TITAN_RUNTIME_2
 class Record_Of_Type;
-class Erroneous_descriptor_t;
+struct Erroneous_descriptor_t;
 #else
 namespace PreGenRecordOf {
   class PREGEN__RECORD__OF__UNIVERSAL__CHARSTRING;
diff --git a/core2/Basetype2.cc b/core2/Basetype2.cc
index 0af50fb2c2af4a748dad2e92dfc832437db03d57..1ddac029f5783313b5f287a4906a5fc9638c986f 100644
--- a/core2/Basetype2.cc
+++ b/core2/Basetype2.cc
@@ -6006,7 +6006,7 @@ int Record_Type::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer&
     }
   }
   
-  delete metainfo;
+  delete[] metainfo;
   
   return dec_len;
 }
diff --git a/xsdconvert/AttributeType.hh b/xsdconvert/AttributeType.hh
index 5a58fe76b2cafc964845dff42ae85d3155af770b..3ab8072e1be92730ef65baf2a2f4ee954396f2cd 100644
--- a/xsdconvert/AttributeType.hh
+++ b/xsdconvert/AttributeType.hh
@@ -100,6 +100,9 @@ public:
     return isAnyAttr;
   }
 
+  void printToFile(FILE* file) {
+    printToFile(file, 0);
+  }
   void printToFile(FILE* file, unsigned level);
 
   void dump(unsigned int depth) const;