dynamic array size in compile time?

Discussion in 'C Programming' started by ir1979, May 4, 2009.

  1. ir1979

    ir1979 Guest

    Hi there,

    I want to declare an array whose size can be calculated in compile
    time. But I as a busy programmer (!) want the compiler to do so. For
    example in the following code:

    #define N 20 //max number of nodes
    #define M 10 //max number of alphabets

    int main()
    {
    const long p2n = pow(2,N)-1;
    char f [p2n][p2n][M+1]={0};
    }


    ,how can I say the compiler that p2n is a constant that can be
    evaluated in compile time (that's like a simple constant).

    Thanks.
     
    ir1979, May 4, 2009
    #1
    1. Advertising

  2. ir1979 <> wrote:
    > Hi there,
    >
    > I want to declare an array whose size can be calculated
    > in compile time. But I as a busy programmer (!) want the
    > compiler to do so. For example in the following code:
    >
    > #define N 20    //max number of nodes
    > #define M 10    //max number of alphabets
    >
    > int main()
    > {
    >     const long p2n = pow(2,N)-1;
    >     char f [p2n][p2n][M+1]={0};


    Use (1ul << expr).

    > }
    >
    > ,how can I say the compiler that p2n is a constant
    > that can be evaluated in compile time (that's like
    > a simple constant).


    The harder problem is finding an implementation that
    supports 10+ terabytes of automatic storage.

    --
    Peter
     
    Peter Nilsson, May 4, 2009
    #2
    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. flamesrock
    Replies:
    8
    Views:
    553
    Hendrik van Rooyen
    Nov 24, 2006
  2. FTSoJ
    Replies:
    6
    Views:
    2,399
    Old Wolf
    May 20, 2005
  3. Nagaraj
    Replies:
    1
    Views:
    920
    Lionel B
    Mar 1, 2007
  4. Carter
    Replies:
    2
    Views:
    530
    Carter
    Mar 4, 2009
  5. Immortal Nephi
    Replies:
    3
    Views:
    692
    James Kanze
    Dec 23, 2009
Loading...

Share This Page