реклама на сайте
подробности

 
 
 
Reply to this topicStart new topic
> Инициализация члена структуры А, типа структуры В ?, В чем проблема?
alux
сообщение Apr 25 2007, 11:46
Сообщение #1


Знающий
****

Группа: Свой
Сообщений: 589
Регистрация: 24-04-05
Пользователь №: 4 447



Компилятор выдает ошибку:
Error[Pe1049]: initializer cannot be specified for a flexible array member .

Использую IAR v.4.12A .

typedef struct menu_entry_s {
unsigned char flags; // see flag definitions above
void (*select)(void *arg, char *name); // routine to call when selected
char name[MENU_ENTRY_NAMELEN]; // name to display for this entry
void *value; // value to pass to select function
} menu_entry_t;

/* Information on a specific menu. Previous is for the menu
that this is a submenu of, or NULL if this is the main menu */

typedef struct menu_s {
unsigned char top_entry; // top displayed entry
unsigned char current_entry; // currently highlighted entry
unsigned char num_entries; // total # of entries in menu
struct menu_s *previous; // previous menu (for backtracking)
menu_entry_t entry[];
} menu_t;
................................................................................
...........................

menu_t sub1_menu = {
.top_entry = 0,
.current_entry = 0,
> .entry = { //!!!!!Error[Pe1049]: initializer cannot be specified for a flexible array member .
{.flags = 0,
.select = my_select,
.name = "s2",
.value = 0,
},
{.flags = 0,
.select = my_select,
.name = "s3",
.value = 0,
},
{.flags = 0,
.select = my_select,
.name = "s4",
.value = 0,
},
},
.num_entries = 3,
.previous = NULL,
};

Что я делаю не так?
Go to the top of the page
 
+Quote Post
CSB
сообщение Apr 25 2007, 12:09
Сообщение #2


Частый гость
**

Группа: Новичок
Сообщений: 100
Регистрация: 9-03-06
Пользователь №: 15 088



Код

typedef struct menu_s {
unsigned char top_entry; // top displayed entry
unsigned char current_entry; // currently highlighted entry
unsigned char num_entries; // total # of entries in menu
struct menu_s *previous; // previous menu (for backtracking)
[b]menu_entry_t entry[];[/b] заменить на [b]menu_entry_t entry[NUMBER];[/b]
} menu_t;

Думаю так. Все-равно заранее известно сколько будет уровней вложения. Или нет?
Go to the top of the page
 
+Quote Post
jorikdima
сообщение Apr 25 2007, 12:14
Сообщение #3


тут может быть ваша реклама
*****

Группа: Свой
Сообщений: 1 164
Регистрация: 15-03-06
Из: Санкт-Петербург/CA
Пользователь №: 15 280



menu_entry_t entry[];

Должны указать размер массива

и

struct menu_s *previous; // previous menu (for backtracking)

слово struct по-моему лишнее
Go to the top of the page
 
+Quote Post
CSB
сообщение Apr 25 2007, 12:19
Сообщение #4


Частый гость
**

Группа: Новичок
Сообщений: 100
Регистрация: 9-03-06
Пользователь №: 15 088



> struct menu_s *previous; // previous menu (for backtracking)
> слово struct по-моему лишнее
Нет. Компилятору нужно знать что это структура.
Go to the top of the page
 
+Quote Post
alux
сообщение Apr 25 2007, 13:33
Сообщение #5


Знающий
****

Группа: Свой
Сообщений: 589
Регистрация: 24-04-05
Пользователь №: 4 447



Цитата(jorikdima @ Apr 25 2007, 12:14) *
menu_entry_t entry[];

Должны указать размер массива


Действительно, все проще оказалось, чем я думал. smile.gif. Надо было просто указать размер массива при объявлении структуры. Спасибо всем ответившим.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0

 


RSS Текстовая версия Сейчас: 20th July 2025 - 20:13
Рейтинг@Mail.ru


Страница сгенерированна за 0.01362 секунд с 7
ELECTRONIX ©2004-2016