Array of Array Initialisation

Discussion in 'C Programming' started by Olaf P., Apr 24, 2007.

  1. Olaf P.

    Olaf P. Guest

    Hi,

    I'm writing an FIR filter. The coeffs for low/high/band pass and band
    stop (LP,HP,BP,BS) are calculated by matlab and exported as header, e.g.

    const int LP_SZ = 33;
    const real64_T LP_H[33] = { ... };

    const int HP_SZ = 33;
    const real64_T HP_H[33] = { ... };

    const int BP_SZ = 33;
    const real64_T BP_H[33] = { ... };

    const int BS_SZ = 33;
    const real64_T BS_H[33] = { ... };

    Now I want to initialize a new array like:

    const real64_T H[4][33] = { LP_H, HP_H, BP_H, BS_H };

    which doesn't compile; The error is

    fir.h:29: error: initializer element is not constant
    fir.h:29: error: (near initialization for `H[0]')

    How can I get this to compile, is there a way? Writing

    const real64_T H[4][33] = { {...}, {...}, {...}, {...} };

    would work, but by change some parameters for FIR filter coeffs I have
    to copy & paste it each time again.

    The goal ist to use the filter coeffs e.g. in the manner of

    int filter_type = 0; // aka LP
    filter_fir(H[filter_type], ...);

    Thanks
    Olaf
     
    Olaf P., Apr 24, 2007
    #1
    1. Advertising

  2. Olaf P. <> wrote:

    > const real64_T H[4][33] = { LP_H, HP_H, BP_H, BS_H };


    > which doesn't compile; The error is


    > fir.h:29: error: initializer element is not constant


    Right; "const" isn't good enough here. Depending on what you need to
    do, the following may be what you want:

    const real64_T *H[4] = { LP_H, HP_H, BP_H, BS_H };

    --
    C. Benson Manica | I *should* know what I'm talking about - if I
    cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
     
    Christopher Benson-Manica, Apr 24, 2007
    #2
    1. Advertising

  3. On Tue, 24 Apr 2007 15:06:54 +0200, Olaf P. wrote:

    > Hi,
    >
    > I'm writing an FIR filter. The coeffs for low/high/band pass and band
    > stop (LP,HP,BP,BS) are calculated by matlab and exported as header, e.g.
    >
    > const int LP_SZ = 33;
    > const real64_T LP_H[33] = { ... };
    > Now I want to initialize a new array like:
    >
    > const real64_T H[4][33] = { LP_H, HP_H, BP_H, BS_H };
    >

    How about
    const real64_T* H[4] = { LP_H, HP_H, BP_H, BS_H };
    (a 4 element array of pointers)

    If you had
    void filter( const real64_T* coeff, real64_T x);
    you could call it like
    filter( H[0], x);
     
    Duncan Muirhead, Apr 24, 2007
    #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. Danny

    Array initialisation

    Danny, Aug 4, 2003, in forum: C++
    Replies:
    16
    Views:
    742
    Web Developer
    Aug 6, 2003
  2. Koster

    Array initialisation

    Koster, Sep 6, 2003, in forum: C Programming
    Replies:
    4
    Views:
    496
    Joe Wright
    Sep 8, 2003
  3. Michael

    Define and array initialisation

    Michael, Jul 7, 2004, in forum: C Programming
    Replies:
    7
    Views:
    314
    Michael
    Jul 7, 2004
  4. Replies:
    3
    Views:
    346
    Al Balmer
    Dec 21, 2006
  5. Tim Clacy
    Replies:
    8
    Views:
    395
    Tim Clacy
    May 30, 2006
Loading...

Share This Page