2016-10-05 2 views
1

구조체에서 가져 오는 ncurses 확장 문자를 표시하려고합니다. 내가 사용하려고하면구조체에서 ncurses 확장 문자 사용

는 : 숫자 값을 저장

#include <ncurses.h> 
struct TEST_STRUCT 
{ 
    int  nCharacter;   // Where I want to store variable for printed character 
    short nTestNumber; // Other stuff in struct 
}; 
TEST_STRUCT sTestData[] = { 
    { '.', 1 },  // Period 
    { ',', 2 },  // Comma 
    { 4194424, 1 } // Vertical Line 
}; 
int main(void) 
{ 
    initscr(); 
    clear(); 
    for(int n = 0; n < 3; n++) 
    { 
     addch(sTestData[n].nCharacter);  // print the characters in the struct 
    } 
    endwin(); 
    return 0; 
} 

:

ACS_VLINE 문자가 제대로 표시되지 않습니다
#include <ncurses.h> 
struct TEST_STRUCT 
{ 
    char nCharacter;  // Where I want to store variable for printed character 
    short nTestNumber; // Other stuff in struct 
}; 
TEST_STRUCT sTestData[] = { 
    { '.', 1 },   // Period 
    { ',', 2 },   // Comma 
    { ACS_VLINE, 1 } // Vertical Line 
}; 
int main(void) 
{ 
    initscr(); 
    clear(); 
    for(int n = 0; n < 3; n++) 
    { 
     addch(sTestData[n].nCharacter); // print the characters in the struct 
    } 
     refresh(); 
    endwin(); 
    return 0; 
} 

,하지만 약간의 장난 후에, 나는 다음과 같은 작품을 발견 이것은 int에있어서 잘못된 것 같지만 작동합니다. 나는 이것을 "올바르게"행하기 위해 어떻게해야 하는가?

답변

0

첫 번째 예제의 문제점은 기호 ACS_VLINE이 배열에서 정적으로 초기화되지 않은 항목 (실제 내용은 initscr에 따라 다름)입니다. 이상하게도, g ++는 그것에 대해 경고하지 않지만, gcc -Wall은 경고를합니다. 이 같은 것을 정의되어

:

#define NCURSES_ACS(c) (acs_map[NCURSES_CAST(unsigned char,c)]) 

#define ACS_VLINE  NCURSES_ACS('x') /* vertical line */ 

두 번째 경우의 정수가 x과 함께 A_ALTCHARSET 금액, 다른 :

2000 년대 초반부터 구별되었습니다
#define NCURSES_ATTR_SHIFT  8 
#define NCURSES_BITS(mask,shift) ((mask) << ((shift) + NCURSES_ATTR_SHIFT)) 

#define A_ALTCHARSET NCURSES_BITS(1UL,14) 

changelog from 2003에 암시된다.