Re: Multidimensional arrays

Discussion in 'C Programming' started by glen herrmannsfeldt, Jan 9, 2004.

  1. Ectomorph wrote:

    (snip)

    > 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
     
    glen herrmannsfeldt, Jan 9, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. d[ - - ]b

    Multidimensional arrays? anything else?

    d[ - - ]b, May 18, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,674
    AlexS
    May 18, 2004
  2. Jay
    Replies:
    1
    Views:
    2,565
    BarryNL
    Jan 30, 2004
  3. geclinke
    Replies:
    1
    Views:
    5,067
    jackie
    Jun 18, 2004
  4. Philipp
    Replies:
    21
    Views:
    1,134
    Philipp
    Jan 20, 2009
  5. Francesco
    Replies:
    2
    Views:
    1,113
    Francesco
    Nov 6, 2009
Loading...

Share This Page