[llvm-commits] CVS: llvm/docs/GetElementPtr.html
Reid Spencer
reid at x10sys.com
Mon Aug 14 20:57:19 PDT 2006
Changes in directory llvm/docs:
GetElementPtr.html updated: 1.6 -> 1.7
---
Log message:
Some more correction to the examples, thanks to Chris Lattner.
---
Diffs of the changes: (+8 -5)
GetElementPtr.html | 13 ++++++++-----
1 files changed, 8 insertions(+), 5 deletions(-)
Index: llvm/docs/GetElementPtr.html
diff -u llvm/docs/GetElementPtr.html:1.6 llvm/docs/GetElementPtr.html:1.7
--- llvm/docs/GetElementPtr.html:1.6 Mon Aug 14 22:46:38 2006
+++ llvm/docs/GetElementPtr.html Mon Aug 14 22:57:05 2006
@@ -77,21 +77,24 @@
<pre>
AType* Foo;
...
- X = Foo[1];</pre>
+ X = &Foo->F;</pre>
<p>it is natural to think that there is only one index, the constant value
<tt>1</tt>. This results from C allowing you to treat pointers and arrays as
equivalent. LLVM doesn't. In this example, Foo is a pointer. That pointer must
be indexed. To arrive at the same address location as the C code, you would
provide the GEP instruction with two indices. The first indexes through the
- pointer, the second index the second element of the array.</p>
+ pointer, the second index the element of the structure just as if it was:</p>
+ <pre>
+ X = &Foo[0].F;</pre>
<p>Sometimes this question gets rephrased as:</p>
<blockquote><i>Why is it okay to index through the first pointer, but
subsequent pointers won't be dereferenced?</i></blockquote>
<p>The answer is simply because memory does not have to be accessed to
perform the computation. The first operand to the GEP instruction must be a
value of a pointer type. The value of the pointer is provided directly to
- the GEP instruction without any need for accessing memory. It must,
- therefore be indexed like any other operand. Consider this example:</p>
+ the GEP instruction as an operand without any need for accessing memory. It
+ must, therefore be indexed and requires an index operand. Consider this
+ example:</p>
<pre>
struct munger_struct {
int f1;
@@ -626,7 +629,7 @@
<a href="http://validator.w3.org/check/referer"><img
src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
<a href="http://llvm.org">The LLVM Compiler Infrastructure</a><br/>
- Last modified: $Date: 2006/08/15 03:46:38 $
+ Last modified: $Date: 2006/08/15 03:57:05 $
</address>
</body>
</html>
More information about the llvm-commits
mailing list