array of array of complex things

Discussion in 'C Programming' started by ma740988@gmail.com, Aug 29, 2006.

  1. Guest

    I'm looking for an equivalent approach to what I would do in C++ such
    to create a vector of vector of complex. I would do :

    typedef std::vector < std::complex < double > > complex_dvec;
    typedef std::vector < complex_dvec > twod_complex_vec;

    int main() {
    twod_complex_vec tdv ( 3, 3 );
    for ( size_t idx ( 0 ); idx < tdv.size(); ++idx )
    {
    for ( size_t jdx ( 0 ); jdx < tdv.front().size(); ++jdx )
    tdv [ idx ] [ jdx ] = idx * jdx ;
    }
    }

    I'm trying to come up with an equivalent C approach to this but I'm
    going around in circles. Source snippet appreaciated.. Thanks in
    advance for
    , Aug 29, 2006
    #1
    1. Advertising

  2. dbtid Guest

    wrote:
    > I'm looking for an equivalent approach to what I would do in C++ such
    > to create a vector of vector of complex. I would do :
    >
    > typedef std::vector < std::complex < double > > complex_dvec;
    > typedef std::vector < complex_dvec > twod_complex_vec;
    >
    > int main() {
    > twod_complex_vec tdv ( 3, 3 );
    > for ( size_t idx ( 0 ); idx < tdv.size(); ++idx )
    > {
    > for ( size_t jdx ( 0 ); jdx < tdv.front().size(); ++jdx )
    > tdv [ idx ] [ jdx ] = idx * jdx ;
    > }
    > }
    >
    > I'm trying to come up with an equivalent C approach to this but I'm
    > going around in circles. Source snippet appreaciated.. Thanks in
    > advance for
    >


    http://www.c-faq.com/aryptr/dynmuldimary.html
    dbtid, Aug 30, 2006
    #2
    1. Advertising

  3. Bill Pursell Guest

    Re: array of array of complex things

    wrote:
    > I'm looking for an equivalent approach to what I would do in C++ such
    > to create a vector of vector of complex. I would do :


    Assuming C89 with no complex types:

    struct complex {
    double r,i;
    };

    struct vector {
    void *data;
    size_t size;
    };

    struct vector a;

    a.data = malloc(NUM_VEC);
    if (a.data == NULL)
    handle_error();

    a.size = NUM_VEC;
    a.data[0] = create_complex_vector();
    .....
    push_value ( 3.4, -1, a.data[0]);

    You'll obviously want to have the ability
    to reallocate space as the vector grows, and
    you'll want a more generic "constructor"
    than create_complex_vector, but the
    above demonstrates some ideas. You
    wouldn't want to call malloc directly on
    a.data, for example. Instead, you'll
    want to write a function that takes perhaps
    an initial size and an allocator function ptr
    as parameters which will create the vector
    for you. You might want to make the vector
    an opaque type and hide the size_t variable
    from the user....lots of ways to do this.
    Bill Pursell, Aug 30, 2006
    #3
    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. news.amnet.net.au
    Replies:
    1
    Views:
    560
    =?UTF-8?b?TMSByrtpZSBUZWNoaWU=?=
    Apr 13, 2004
  2. Stanimir Stamenkov
    Replies:
    2
    Views:
    734
    Stanimir Stamenkov
    Oct 25, 2005
  3. =?Utf-8?B?V2lsbGlhbSBTdWxsaXZhbg==?=

    vs2005 publish website doing bad things, bad things

    =?Utf-8?B?V2lsbGlhbSBTdWxsaXZhbg==?=, Oct 25, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    589
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Oct 25, 2006
  4. Robert Mark Bram
    Replies:
    0
    Views:
    673
    Robert Mark Bram
    Feb 4, 2007
  5. Kottiyath

    How complex is complex?

    Kottiyath, Mar 18, 2009, in forum: Python
    Replies:
    22
    Views:
    742
Loading...

Share This Page