Commits

George Russell committed 96308a6

Add pragma section + update compatibility comment

Comments (0)

Files changed (1)

 == Welcome ==
 
 ConstCPP is C++ with the const modifier on, all of the time. Except when you 
-use mutable instead.
+use mutable instead. Or disable ConstCPP via a pragma to support normal
+C++ in ConstCPP code.
 
 This is a hacked together compiler patching clang/LLVM 2.9 and is in no way
 actually tested, rigourously designed, or necessarily useful or usable.
-It is also incompatible with ~99% of existing C++ code, including standard headers...
+
 
 Inspired by a tweet from @tim_angus 
 {{{
 
 }}}
 
+Pragmas permit the control of when ConstCPP is enabled or disabled within
+program source. Normal C++ can invoke ConstCPP defined functions, and vice-versa.
+
+{{{
+#!c++
+/* Turn ConstCPP off and include existing header */
+#pragma CONST_CPP OFF
+#include <cstdio>
+
+void sum(int* a, int* b, int* r)
+{
+    *r = *b + *a;   
+}
+
+/* Turn ConstCPP on again */
+#pragma CONST_CPP ON
+
+void sum(int* a, int* b, mutable int*  r)
+{
+    *r = *b + *a + 1;   
+}
+
+int main(int argc, char** argv) {
+    // Call normal C++ sum
+    mutable int a = 2,b =2,r = 0;
+    sum(&a,&b,&r);
+    // Call ConstCPP sum
+    int a2 = 2, b2 = 2;
+    mutable int r2 = 0;
+    sum(&a2,&b2,&r2);
+    
+    printf("r(4) == %d, r2(5) == %d\n",r,r2);
+    
+    return 0;
+}
+
+}}}
+
 === Compiling and Using ConstCPP ===
 
 It builds just like clang / LLVM.