-2

I have a section of c++ code in keil uvision5 that is getting error 28: expression must have a constant value. I am trying to figure out how to fix it.

this is the line (inside of a function) that it is happening on:

osPoolDef_t pool_def = { queue_def->queue_sz,  queue_def->item_sz};

it does not like the variables queue_sz or item_sz.

here is the definition of osPoolDef_t:

typedef const struct os_pool_def  {
  uint32_t                 pool_sz;    /*  number of items (elements) in the pool */
  uint32_t                 item_sz;    /*  size of an item */
  void                     *pool;      /*  pointer to memory for pool */
} osPoolDef_t;

and queue_def is a pointer to osMailQDef_t shown below:

typedef const struct os_mailQ_def  {
  uint32_t                queue_sz;    /*  number of elements in the queue */
  uint32_t                 item_sz;    /*  size of an item */
  struct os_mailQ_cb **cb;
} osMailQDef_t;

hopefully that is enough information.

It seems that the problem is that I am not using c99 anymore, but the code worked fine for that file when I used c99. Is there a way to force the compilation of just that file to be done with c99?

user3729617
  • 113
  • 1
  • 14
  • 1
    Are you trying to do that initialization outside a function? – Mat Jul 02 '14 at 10:01
  • 2
    in C you must have a constant value here. But not in C++. Are you sure you are using a C++ compiler? – M.M Jul 02 '14 at 10:04
  • @MattMcNabb it is a c file but I am using a c++ compiler. When I compiled using c99 it worked but my main file is c++ so I am not using c99 anymore. – user3729617 Jul 02 '14 at 10:05
  • perhaps your compiler decides to create .c files as C – M.M Jul 02 '14 at 10:06
  • Try to include the c file within a cpp file. – Wolf Jul 02 '14 at 10:07
  • So apparently `{ queue_def->queue_sz, queue_def->item_sz}` is not a constant expression and thus can't be used for static initialization. @MattMcNabb _'But not in C++'_ Depends on where this line is actually placed. – πάντα ῥεῖ Jul 02 '14 at 10:23
  • I changed it to a cpp file and that just created a bunch of other problems. – user3729617 Jul 02 '14 at 11:04

1 Answers1

0

You can force the armcc compiler to use C99 with the --c99 option.

Sivar
  • 56
  • 3