This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Static declaration error

Code: static unsigned int timer[num_timers];

Error: TIMER_MODULE.C(6): error C221: non-constant case/dim expression

An error has been generated while declaring an array in static.

Or else help me out with " an initial value of the array's element should be zero." what should I do?

Parents
  • You have tried to use a variable "num_timers" to specify the size of an array.

    You can't.

    You need to use a constant value.

    Valid:

    static unsigned int timer[10];
    
    #define NUM_TIMERS 10
    
    static unsigned int timer[NUM_TIMERS];
    
    enum {
        NUM_TIMERS = 10;
    };
    
    static unsigned int timer[NUM_TIMERS];
    

Reply
  • You have tried to use a variable "num_timers" to specify the size of an array.

    You can't.

    You need to use a constant value.

    Valid:

    static unsigned int timer[10];
    
    #define NUM_TIMERS 10
    
    static unsigned int timer[NUM_TIMERS];
    
    enum {
        NUM_TIMERS = 10;
    };
    
    static unsigned int timer[NUM_TIMERS];
    

Children
No data