【发布时间】:2014-08-06 11:40:35
【问题描述】:
我在嵌入式系统中创建了一个菜单结构如下:
struct DisplayMenu
{
short int MenuTitle; // Menu title text offset - the title used in the calling menu
char NoOfSubmenuItems; // number of submenuItems in this menu ? static!
char PositionInLastMenu; // position in previous menu - helps restore previous menu screen
struct DisplayMenu *PreviousMenu; // pointer to previous menu - need to be const?
struct DisplayMenu *NextMenu[MAX_NO_OF_SUBMENU_ITEMS]; // array of pointers to submenus structs - Null if no submenu...function call instead
void (*MenuFunctionsArray[MAX_NO_OF_SUBMENU_ITEMS])(void); // array of function pointers - called if no submenu. Check if null
const short int *SubMenuText; // pointer array of text offsets for submenu text - no set length variable length array allowed at end of struct in GCC at least
};
因此为早期原型设计实例化:
const short int MainMenuTextStrings[]= { tSTATUS, tSETUP, tStartOfTextString, tANALYSER, tUNITS, tEndOfTextString, tUNITS, tALARM, tSCREEN, tREPORTS, tSERVICE, tStartOfTextString, tMANUAL, tAIR, tZERO, tEndOfTextString, tStartOfTextString, tMANUAL, tEndOfTextString, NULL }; // needs a new text entry
// main menu struct
struct DisplayMenu MainMenu =
{
tMENU, // Menu title
0, // number of submenus
0, // no previous menu
NULL, // no previous menu to point to
{ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, // to be set up later
{ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, // function pointers
MainMenuTextStrings
};
以期稍后初始化功能/菜单指针等
使用 GCC 可以编译,但是当代码运行时(已经启动并运行了一个非动态菜单系统)IDE(MPLABX)正在努力查看 MainMenu 的内容,当我尝试运行函数 DisplayMenuItems (如下)我无法通过它
谁能发现我定义结构和实例化它的方式有什么问题?
我打算使用以下函数来使用结构体显示项目:
void DisplayMenuItems(struct DisplayMenu* Menu)
{
while(*(Menu->SubMenuText) != NULL)
{
if(*(Menu->SubMenuText) == tStartOfTextString) //if a few text strings need to be concatenated on one line
{
while(*(Menu->SubMenuText++) != tEndOfTextString) //keep printing until you find the EndofTextString ident
WriteStringToDisplay((char*) &pText[Config.ucLanguage][*(Menu->SubMenuText)], SmallFont);
}
else /*if(*(Menu->SubMenuText) != NULL) */
{
WriteStringToDisplay((char*) &pText[Config.ucLanguage][*(Menu->SubMenuText)++], SmallFont);
}
DisplayCarriageReturn(2,SmallFont); // try and remove this eventually? Just increment Lcd.ucLine instead
}
}
GCC 可能会让我摆脱一些我不应该在这里做的事情,所以任何提示都非常感谢!
非常感谢
【问题讨论】:
-
那个演员和埋葬的
*(Menu->SubMenuText)++看起来一点都不健康。 -
while(*(Menu->SubMenuText) != NULL)的目的是什么?*(Menu->SubMenuText)返回short int值。将其与NULL进行比较完全没有意义。