瀏覽代碼

Merge pull request #6500 from JamesDeFabia/9877CPP_pointers

HPCC-9877 Clarify use of const in BEGINC++ docs

Reviewed-by: Gavin Halliday <ghalliday@hpccsystems.com>
Gavin Halliday 10 年之前
父節點
當前提交
acdbdd0057
共有 1 個文件被更改,包括 21 次插入0 次删除
  1. 21 0
      docs/ECLLanguageReference/ECLR_mods/SpecStruc-BeginC++.xml

+ 21 - 0
docs/ECLLanguageReference/ECLR_mods/SpecStruc-BeginC++.xml

@@ -134,8 +134,10 @@ LINKCOUNTED DATASET(r)  ABC -&gt; size32_t countAbc, const byte * * abc
     <programlisting><emphasis role="bold">ECL                C++ [Linux in brackets]</emphasis>
 DATA xyz           size32_t &amp; __lenResult, void * &amp; __result
 STRING xyz         size32_t &amp; __lenResult, char * &amp; __result
+CONST STRING xyz   size32_t lenXyz, const char * xyz
 QSTRING xyz        size32_t &amp; __lenResult, char * &amp; __result
 UNICODE xyz        size32_t &amp; __lenResult, UChar * &amp; __result
+CONST UNICODE xyz  size32_t &amp; __lenResult, const UChar * &amp; __result
 DATA&lt;nn&gt; xyz       void * __result
 STRING&lt;nn&gt; xyz     char * __result
 QSTRING&lt;nn&gt; xyz    char * __result
@@ -159,6 +161,25 @@ STREAMED DATASET(r)
 
     <programlisting>void process(size32_t &amp; __lenResult, char * &amp; __result,
              size32_t lenValue, char * value, int len);</programlisting>
+
+    <para>A function that takes a string parameter should also have the type
+    prefixed by <emphasis role="bold">const</emphasis> in the ECL code so that
+    modern compilers don't report errors when constant strings are passed to
+    the function. </para>
+
+    <programlisting>BOOLEAN isUpper(const string mystring) := BEGINC++
+  size_t i=0;
+  while (i &lt; lenMystring)
+  {
+    if (!isupper((byte)mystring[i]))
+        return false;
+    i++;
+  }
+  return true;
+ENDC++;
+isUpper('JIM');
+
+</programlisting>
   </sect2>
 
   <sect2 id="BeginCPP_Available_Options">