diff options
author | Bill Wendling <isanbard@gmail.com> | 2006-12-17 11:40:40 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2006-12-17 11:40:40 +0000 |
commit | b0a9d1b9bc3180e7f5e7ca3c0c1a798414e942e8 (patch) | |
tree | 7f0193cf3cf555f36b7306f5936ce1f0d44ff7d2 /docs/CodingStandards.html | |
parent | f2174da7132b1a3ce81d8a154a20c1285b5b15dd (diff) | |
download | llvm-b0a9d1b9bc3180e7f5e7ca3c0c1a798414e942e8.tar.gz llvm-b0a9d1b9bc3180e7f5e7ca3c0c1a798414e942e8.tar.bz2 llvm-b0a9d1b9bc3180e7f5e7ca3c0c1a798414e942e8.tar.xz |
Added example of how to code print() methods so that they will disappear
from the code if "cnull" is passed into them.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32641 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'docs/CodingStandards.html')
-rw-r--r-- | docs/CodingStandards.html | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/docs/CodingStandards.html b/docs/CodingStandards.html index 5b65fbc637..97e21fa65c 100644 --- a/docs/CodingStandards.html +++ b/docs/CodingStandards.html @@ -509,7 +509,7 @@ library. There are two problems with this:</p> more pressure on the VM system on low-memory machines.</li> </ol> -<table> +<table align="center"> <tbody> <tr> <th>Old Way</th> @@ -520,8 +520,10 @@ library. There are two problems with this:</p> <td align="left"><pre>#include "llvm/Support/Streams.h"</pre></td> </tr> <tr> - <td align="left"><pre>DEBUG(std::cerr << ...);</pre></td> - <td align="left"><pre>DOUT << ...;</pre></td> + <td align="left"><pre>DEBUG(std::cerr << ...); +DEBUG(dump(std::cerr));</pre></td> + <td align="left"><pre>DOUT << ...; +dump(DOUT);</pre></td> </tr> <tr> <td align="left"><pre>std::cerr << "Hello world\n";</pre></td> @@ -536,6 +538,12 @@ library. There are two problems with this:</p> <td align="left"><pre>llvm::cin >> Var;</pre></td> </tr> <tr> + <td align="left"><em>N/A</em></td> + <td align="left"><pre>llvm::cnull >> Var;</pre> + <ul><i>N.B.</i> Eats up argument <tt>Var</tt> outputting + nothing.</ul></td> + </tr> + <tr> <td align="left"><pre>std::ostream</pre></td> <td align="left"><pre>llvm::OStream</pre></td> </tr> @@ -552,9 +560,14 @@ library. There are two problems with this:</p> // ... print(std::cerr);</pre></td> <td align="left"><pre>void print(std::ostream &Out); +void print(std::ostream *Out) { if (Out) print(*Out) } // ... -print(*llvm::cerr.stream());</pre></td> - </tbody> +print(llvm::cerr);</pre> + +<ul><i>N.B.</i> The second <tt>print</tt> method is called by the <tt>print</tt> +expression. It prevents the execution of the first <tt>print</tt> method if the +stream is <tt>cnull</tt>.</ul></td> + </tbody> </table> </div> |