From: Bill Wendling
Date: Sun, 17 Dec 2006 11:40:40 +0000 (+0000)
Subject: Added example of how to code print() methods so that they will disappear
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=b0a9d1b9bc3180e7f5e7ca3c0c1a798414e942e8;p=oota-llvm.git
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
---
diff --git a/docs/CodingStandards.html b/docs/CodingStandards.html
index 5b65fbc637c..97e21fa65cc 100644
--- a/docs/CodingStandards.html
+++ b/docs/CodingStandards.html
@@ -509,7 +509,7 @@ library. There are two problems with this:
more pressure on the VM system on low-memory machines.
-
+
Old Way |
@@ -520,8 +520,10 @@ library. There are two problems with this:
#include "llvm/Support/Streams.h" |
- DEBUG(std::cerr << ...); |
- DOUT << ...; |
+ DEBUG(std::cerr << ...);
+DEBUG(dump(std::cerr)); |
+ DOUT << ...;
+dump(DOUT); |
std::cerr << "Hello world\n"; |
@@ -535,6 +537,12 @@ library. There are two problems with this:
std::cin >> Var; |
llvm::cin >> Var; |
+
+ N/A |
+ llvm::cnull >> Var;
+ N.B. Eats up argument Var outputting
+ nothing. |
+
std::ostream |
llvm::OStream |
@@ -552,9 +560,14 @@ library. There are two problems with this:
// ...
print(std::cerr);
void print(std::ostream &Out);
+void print(std::ostream *Out) { if (Out) print(*Out) }
// ...
-print(*llvm::cerr.stream()); |
-
+print(llvm::cerr);
+
+N.B. The second print method is called by the print
+expression. It prevents the execution of the first print method if the
+stream is cnull.
+