本文介绍了关于REAL Expert结构初始化的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,让我们说有一个功能菜单结构声明

就像这样(因为我基本上这样做):


typedef struct function_item {

char * descrip;

void(* function)(void);

} t_function_item;


typedef struct function_menu {

unsigned short num_items;

unsigned short default_item;

char * title_prompt;

t_function_item * function_items;

} t_function_menu;


现在有时候(实际上几乎所有时间)我想把它初始化为

字面值。所以我就是这样做的(有点)本地函数

选择

a函数并运行它(代码没有说明问题省略):


void my_function_1(void){

}


void my_function_2(void){

}


unsigned short run_function_menu(t_function_menu * function_menu){

}


void select_function(void ){

静态t_function_menu my_function_menu =

{0,0,我的函数菜单};

static t_function_item my_function_items [] = {

{" My Function 1" my_function_1},

{" My Function 2" my_function_2},

{NULL,NULL } $;

my_function_menu.function_items = my_function_items;


run_function_menu(& my_function_menu);

}


我的问题是:出于某种原因,如果我尝试初始化菜单

结构一下子,在我看来似乎是一个合法的

初始化,如下所示:


static t_function_menu my_function_menu =

{0,0," My Function Menu" ;,(t_function_item []){

{" My Function 1",my_function_1},

{" My Function 2" my_function_2},

{NULL,NULL}}};


我只是得到了一堆语法错误,但对我来说,上面似乎是

功能上与我实际需要做的相同,如

中所示,select_function()示例让事情发挥作用...为什么我会获得错误,以及
获取错误,以及有没有办法在一次初始化分配中初始化这样的结构

?我在这里错过了什么?


---

William Ernest Reid

解决方案



有什么错误?


代码看起来很好。您使用的是C99编译器吗?


-

Ian Collins。




有什么错误?


代码看起来很好。您使用的是C99编译器吗?



不要给巨魔喂食。




对不起,周日下午很安静!


-

Ian Collins。

OK, let''s say that have a function menu structure declaration
like this (since I basically do):

typedef struct function_item {
char *descrip;
void(*function)(void);
} t_function_item;

typedef struct function_menu {
unsigned short num_items;
unsigned short default_item;
char *title_prompt;
t_function_item *function_items;
} t_function_menu;

Now sometimes (really just about all the time) I want to initialize it to
literal values. So this is how I do it (sort of) for a local function that
selects
a function and runs it (code that doesn''t illustrate the question elided):

void my_function_1(void) {
}

void my_function_2(void) {
}

unsigned short run_function_menu(t_function_menu *function_menu) {
}

void select_function(void) {
static t_function_menu my_function_menu=
{0,0,"My Function Menu"};
static t_function_item my_function_items[]={
{"My Function 1",my_function_1},
{"My Function 2",my_function_2},
{NULL,NULL}};
my_function_menu.function_items=my_function_items;

run_function_menu(&my_function_menu);
}

My question is: for some reason if I try to initialize the menu
structure in one fell swoop, with what seems to me to be a legal
initialization, like this:

static t_function_menu my_function_menu=
{0,0,"My Function Menu",(t_function_item []){
{"My Function 1",my_function_1},
{"My Function 2",my_function_2},
{NULL,NULL}}};

I just get a bunch of syntax errors, but to me, the above seems
to be functionally identical to what I actually have to do as shown in
the select_function() example to get the thing to work...why am I
getting the errors, and IS there some way to initialize such a structure
in one initialization assignment? What am I missing here?

---
William Ernest Reid

解决方案

What errors?

The code looks fine. Are you using a C99 compiler?

--
Ian Collins.



What errors?

The code looks fine. Are you using a C99 compiler?

Don''t feed the troll.


Sorry, quiet Sunday afternoon!

--
Ian Collins.


这篇关于关于REAL Expert结构初始化的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 11:33