我正在编写基于MDK-ARM
环境中的状态机的embedded C
代码,该环境使用RealView
(基于ARMCC)编译器。MDK-ARM C错误:表达式必须有一个常数值
IDE产生一个错误:
error: #28: expression must have a constant value.
的代码部分如下:
struct wspace
{
struct netimer period;
struct nequeue deferred;
struct nevent *deferred_queue_storage[EPA_EEPROM_QUEUE_SIZE];
struct nepa *producer;
struct event_i2c_transfer transfer;
uint32_t i2c_retry;
uint8_t i2c_buffer[3];
uint32_t address;
uint8_t *raw_buffer;
uint32_t size;
uint32_t idx;
uint32_t max_size;
uint32_t dev_id;
};
static naction state_init_eeprom(struct nsm * sm, const struct nevent * event) {
struct wspace * ws = nsm_wspace(sm);
switch (event->id) {
case NSM_INIT : {
struct nequeue_define deferred_queue =
**NEQUEUE_DEF_INIT(ws->deferred_queue_storage, sizeof(ws->deferred_queue_storage));** // this is the line pointed by compiler
netimer_init(&ws->period);
nequeue_init(&ws->deferred, &deferred_queue);
ws->transfer.super = g_default_event;
ws->transfer.super.producer = nepa_get_current();
ws->transfer.dev_id = EEPROM_I2C_ID;
ws->transfer.timeout_ms = EEPROM_I2C_TIMEOUT_MS;
ws->max_size = 8 * 1024;
ws->dev_id = EEPROM_I2C_ID;
return (naction_transit_to(sm, state_idle));
}
default : {
return (naction_ignored());
}
}
}
重要的定义:
#define NEQUEUE_SIZEOF(elements)
(sizeof(struct nevent * [elements]))
#define NEQUEUE_DEF_INIT(storage, size)
{storage, size}
struct nequeue_define
{
struct nevent ** storage;/**<@brief Allocated memory storage */
size_t size; /**<@brief Size of queue in bytes */
};
struct nequeue
{
struct nqueue queue;
#if (CONFIG_REGISTRY == 1)
ncore_reg min;
#endif
#if (CONFIG_API_VALIDATION == 1)
unsigned int signature;
#endif
};
一切,我在这个题目中是相关事实上常数变量不能被assi即使之前被初始化,也会将其作为初始化器的数组或成员的元素。
有没有人有想法如何克服这个问题?
感谢,我认为过,但不敢肯定。仍然不清楚如何去做。 – PredragN
我不确定,但我认为我应该将指针作为结构的第一个成员,但不知道如何去做?想法似乎没问题,但你能更精确吗?如果你仔细看看wspace结构,你可以看到struct nevent * deferred_queue_storage [EPA_EEPROM_QUEUE_SIZE]是指针的区域,其中每个指针代表一个事件缓冲区。我暂时做的是试图将软件从GCC移植到Keil RealView编译器。这个NEQUEUE_DEF_INIT应该只是队列初始化器。 – PredragN
我认为你只需要避免使用NEQUEUE_DEF_INIT宏。你有没有尝试设置存储和大小像user694733建议? –