Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: Multidimensional arrays

Thread Tools

Re: Multidimensional arrays

glen herrmannsfeldt
Posts: n/a
Ectomorph wrote:


> Thank you for your reply. I anticipated that this might be difficult
> to describe! Unless I have misread the very informative example that
> you kindly posted, it appears that you actually specify at compile
> time the number of dimensions (i.e. the rank) of the tensor. I need
> something slightly more complex: the number of dimensions can only be
> known at run time.
> new_excitation(i1,i2) = i1 * 10 + i2
> The new_excitation variable appears just to be of two-dimensional
> (i.e. matrix) type, which can be accessed with the natural syntax
> (x,y).

(big snip)

> Naturally I could just specify a 3D array at compile time and then
> access with (x,y,z) but unfortunately I do not know whether the array
> will be 1D, 2D, 3D etc. prior to running the code. C is just awful for
> expressing such situations, what I am trying to discover is whether
> Fortran is any better at it?

I think C would do better than Fortran, though natural syntax is
still not obvious to me. If you don't know how many dimensions
it has, you can't use natural syntax.

In C, you can make a (pointer to)**n, that is, any depth of pointer
to a variable that you need. If cast to the appropriate type, a
variable can be dereferenced using C's array syntax.

More obvious to me, though, is that you might have the subscripts
in an array, and need to reference an element of the array that
way. The offset calculation into a single dimension array isn't
so hard to do at that point.

-- glen

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
casting pointers/arrays to multidimensional arrays Francesco C++ 2 11-06-2009 09:04 AM
Multidimensional arrays and arrays of arrays Philipp Java 21 01-20-2009 08:33 AM
Multidimensional arrays in Struts form? geclinke Java 1 06-18-2004 03:31 PM
Multidimensional arrays? anything else? d[ - - ]b ASP .Net 2 05-18-2004 12:17 PM
Cast to multidimensional arrays Jay Java 1 01-30-2004 04:27 PM