2010-12-04 38 views
1

我的編譯器,MPLAB C30(GCC V3.23)未編譯此代碼:我的編譯器優化出來的東西,它不應該

if(font_info.flags & FONT_LOWERCASE_ONLY) 
    ch = tolower(ch); 
if(font_info.flags & FONT_UPPERCASE_ONLY) 
    ch = toupper(ch); 

它不產生彙編輸出(以某種方式優化出來)和我無法弄清楚爲什麼。

正確,據我所定義的一切,我可以看到:

#define FONT_LOWERCASE_ONLY 1 
#define FONT_UPPERCASE_ONLY 2 

struct FontEntry 
{ 
int id; 
unsigned char width, height; 
const char *name; 
const char *lookup; 
const char *data; 
int flags; 
}; 

struct FontEntry fonts[NUM_FONTS + 1] = { 
{ 0, 8, 14, "Outlined8x14", &font_lookup_outlined8x14, &font_data_outlined8x14, 0 }, 
{ 1, 8, 8, "Outlined8x8", &font_lookup_outlined8x8, &font_data_outlined8x8, FONT_UPPERCASE_ONLY }, 
{ 2, 8, 8, "Tiny5x5", 0, 0, 0 }, // not yet implemented 
{ -1 } // ends font table 
}; 

我使用的功能是:

void write_char(char ch, unsigned int x, unsigned int y, int flags, int font) 
{ 
int i, yy, addr_temp, row, row_temp, xshift; 
uint16_t and_mask, or_mask, level_bits; 
struct FontEntry font_info; 
char lookup; 
fetch_font_info(ch, font, &font_info, &lookup); 
    // ... 
} 

fetch_font_info的定義:

int fetch_font_info(char ch, int font, struct FontEntry *font_info, char *lookup) 
{ 
// First locate the font struct. 
if(font > SIZEOF_ARRAY(fonts)) 
    return 0; // font does not exist, exit. 
// Load the font info; IDs are always sequential. 
*font_info = fonts[font]; 
// Locate character in font lookup table. (If required.) 
if(lookup != NULL) 
{ 
    *lookup = font_info->lookup[ch]; 
    if(lookup == 0xff) 
    return 0; // character doesn't exist, don't bother writing it. 
} 
return 1; 
} 

什麼我做錯了嗎?

+4

顯示font_info的聲明。 – hirschhornsalz 2010-12-04 14:54:07

+0

您需要展示更多的代碼,其中第一個塊出現 – fazo 2010-12-04 15:06:12

回答

0

是否有可能在的write_char()(因爲您發佈的write_char()不是您真正編譯的內容;發生了一些編輯,因此很難知道)返回代碼?如果你表現從fetch_font_info()回報那麼問題可能是由錯誤的測試字符cuased

指向lookup

if(lookup == 0xff) 

應該

if(*lookup == 0xff) 

與竊聽測試,fetch_font_info()將始終返回0,如果查找是非空。

2

由於FONT_LOWERCASE_ONLY和FONT_UPPERCASE_ONLY不爲0,因此font_info.flags必須始終爲0(或者在低兩位中不包含任何1)。即使你沒有這樣定義它們,編譯器也可以很聰明地評估它們如何評估「常量」。

我看到你的字體數組在flag部分有幾個0,所以我打賭你在編譯時有一個硬編碼引用。