[cfe-dev] Question about array accesses

Prateek Saxena thisisprateeksaxena at gmail.com
Fri Feb 14 02:06:38 PST 2014


Hi,

I guess I left out far too many details regarding the background to the
question for it to come across as being a general C++ question.
What I meant is follows:
I am trying to write a memory mapper using AST Traversal whereby I need to
figure out which all memory locations are getting used.
So, while traversing the AST, since the C semantics imply that
multi-dimensional arrays gets treated as pointers with multiple
dereferences, the AST also gets created in the same way.
My original question was to ask for a simple way to extract out the size of
the pointer dimensions from the AST.

I apologise for the incomplete formulation of my question.

Regards,
Prateek


On Fri, Feb 14, 2014 at 2:17 PM, Csaba Raduly <rcsaba at gmail.com> wrote:

> Hi Prateek,
>
> On Thu, Feb 13, 2014 at 7:26 AM, Prateek Saxena
> <thisisprateeksaxena at gmail.com> wrote:
> > Hi.
> >
> > Given a multi-dimensional array like
> > int a[3][5][6];
> >
> > what would be a good way of calculating the offset of an element like
> > a[1][1][1] from the base pointer to a ?
>
> This is a mailing list for discussing clang the C/C++/ObjC compiler.
> Your question belongs to a forum for general C++ questions, for
> example Stackoverflow.
>
> Have you tried
>
> &(a[1][1][1]) - &(a[0][0][0])
>
> ?
>
> Csaba
> --
> GCS a+ e++ d- C++ ULS$ L+$ !E- W++ P+++$ w++$ tv+ b++ DI D++ 5++
> The Tao of math: The numbers you can count are not the real numbers.
> Life is complex, with real and imaginary parts.
> "Ok, it boots. Which means it must be bug-free and perfect. " -- Linus
> Torvalds
> "People disagree with me. I just ignore them." -- Linus Torvalds
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140214/d026221e/attachment.html>


More information about the cfe-dev mailing list