GCC compiler hacks

Me and the GCC compiler have had a long history together, and in that time we have rarely seen eye to eye. We have major disagreements with the interpretation and implementation of the c/c++ standards and also the ABI. One of us has to yield and it will not be me, so onward with the compiler mods/hacks.

1. character array initialization and the null terminator
c++ forbids initializing a character array with a string literal where the size of the string would exceed the size of the character array, the string length includes the null terminator making it impossible to initialize a character array without a null terminator at the end.

Index: typeck2.c
==================================================================
--- typeck2.c
+++ typeck2.c
@@ -1082,13 +1082,13 @@
 	      size = (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
 	      /* In C it is ok to subtract 1 from the length of the string
 		 because it's ok to ignore the terminating null char that is
 		 counted in the length of the constant, but in C++ this would
 		 be invalid.  */
-	      if (size < TREE_STRING_LENGTH (init))
+	      /*if (size < TREE_STRING_LENGTH (init))
 		permerror (loc, "initializer-string for array "
-			   "of chars is too long");
+			   "of chars is too long"); */
 	    }
 	  return init;
 	}
     }
 

Exe Modifer patch
Since building gcc from source is super hard I decided just to directly modify cc1plus.exe, after locating the string “initializer-string for array “, I then searched for the code that made reference to it, and then it was a simple matter of nopping out the offending code. My non-complaint source code now compiles, and all it good.

 

Advertisements