完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
这是函数的一部分。文本是一个指针传递到函数。gfxxxCHAR * GETLIGAGEXETCIN PTR(const gfxxxCHAR *(*text))i,并在这里得到一个例外:如果(文本)!{NULL){返回(GFXXXCHAR *)文本[语言];} {{返回(GFXXXCHAR *)“”;//没有字符串?现在指针明显坏了。但是如何呢?它不是空的。需要一定范围内好吗?编译器有测试功能吗?我宁可排空格,也不例外。
以上来自于百度翻译 以下为原文 This is part of a function. text is a pointer passes in to the function. GFX_XCHAR *getLanguageStringPtr(const GFX_XCHAR *(*text)) I and getting an exception here: if(text != NULL) { return (GFX_XCHAR *)text[language]; } else { return (GFX_XCHAR *)""; // No string? } Now the pointer is obviously Bad. But how? It is Not Null. does it need to be withing a certain range to be good? doe the Compiler have a test function? I would rather have to line blank then an exception. |
|
相关推荐
11个回答
|
|
红色应该在那里吗?GFXXXCHAR * GETLIGAGEXETCIN PTR(const gfxxxCHAR *(*text))
以上来自于百度翻译 以下为原文 Should the red * be there? GFX_XCHAR *getLanguageStringPtr(const GFX_XCHAR *(*text)) |
|
|
|
是的,它是一组指针。代码很好。我只是想弄清楚如何才能不通过一个坏指针。坏指针是我的错误。
以上来自于百度翻译 以下为原文 Yes it is an array of pointers. The code is good. I am just trying to figure out how to figure out how to no pass a bad pointer. The bad pointers are my bugs. |
|
|
|
如果是一个指针表,那么
以上来自于百度翻译 以下为原文 If it's a table of pointers, then maybe if ( (text != NULL) && (*text != NULL) ) |
|
|
|
|
|
|
|
指针可以指向任何地方。除了微不足道的NulLand对齐检查(或者检查物理内存的界限)之外,你不能真正判断指针是好还是坏。如果“文本[语言]”从一个随机位置抓取一个指针,在返回之后试图访问它的代码将崩溃。
以上来自于百度翻译 以下为原文 The pointer may point anywhere. Except the trivial not-null and alignment checks (or perhaps checking the bounds of physical memory), you cannot really tell if the pointer is good or bad. If the "text[language]" grabs a pointer from a random place, the code that tries to access it after the return will crash. |
|
|
|
你能给我们一个更完整的例子吗?指针的数组与指针指针的数组不一样。
以上来自于百度翻译 以下为原文 Can you give us a more complete example on how getLanguageStringPtr() is used? An array of pointers is not the same as pointer-to-pointer. |
|
|
|
我想我应该知道不要发布一个完整的例子。当我从指针表中拔出字符串数组并把它弄乱的时候,这个问题就发生了。所有的打印都是SNPrTfF()和其他不会逃跑的函数。在函数调用所有函数时,垃圾更容易调试。 以上来自于百度翻译 以下为原文 #define GFX_XCHAR char; #define NUMBER_OF_LANGUAGES 3 static const GFX_XCHAR const *btnCaptionCancel [NUMBER_OF_LANGUAGES] = {"Cancel","",""}; GFX_XCHAR *pointer; pointer = getLanguageStringPtr(btnCaptionCancel); //****************************************************************************** // Function: getLanguageStringPtr() // // Description: returns a pointer to the string of the current language, // it returns string [0] if the current language string is "" // // Parameter(s): // text : a pointer to a an array of language text // // Return: pointer to the string // //****************************************************************************** GFX_XCHAR *getLanguageStringPtr(const GFX_XCHAR *(*text)) { uint16_t language; if(text != NULL) { // if language item is blank use English if(text[ext_eeprom.language][0] != ' |