2014년 6월 24일 화요일

C 언어 에러 삽질 방지

오늘부터 자주 보는 에러에 대한 나의 삽질내역을 기록하겠다.


warning: implicit declaration of function '함수'
1.발생 이유: 함수선언을 다른 곳, 현재 코드보다 아래에 해두고 가져다 쓸 때 
2.해결방법 : 사용하는 위치 보다 아래에 정의된 함수를 가져다 쓸 때는 해당 파일 또는 include 하는 헤더파일에다가 함수 원형을 선언해두자. 다른 파일에 있다면 extern 하여 사용 하자.
3.여담: 워닝인 이유는 컴파일러가 알아서 찾아주기때문. 컴파일러가 구리면 error로 띄워주는듯 하다.

warning: nested extern declaration of '함수명'
1.발생이유: 이제껏 상위 implicit declaration of function  의 여파로 생겨 났던 것 밖에 없다.
2.해결방법 : 위의 워닝을 해결하라
3.여담: 찾아도 잘안나오네 ㅠㅠ

warning: label 'defualt' defined but not used
1.발생 이유: 스위치 문에서 default를 defualt로 적어서 나는 워닝
2.해결방법 : 오타를 수정하자 무지막지하게 부끄러운 일이다..(*-_-*)
3.여담: 이걸 상사에게 물어봤다가 얼굴이 빨개졌다. 부끄러워서...

warning: return makes integer from pointer without a cast
1.발생 이유: 리턴 값이 int인 함수내에서 다른 자료형으로 리턴을 했을 때
2.해결방법 : 꼭 리턴해야 하는 의미있는 값일경우(unsigned 라던지) return (int)변수명;
return NULL; <- 이런걸 적어놨다면 그냥 -1로 리턴하고 해당 함수 콜 하는 부분 다음에 
if(ret < 0) 를 사용하여 예외처리를 하자(ret는 보통 return 의 줄임말. return 예약어니까 변수명으로 쓸수 없다)
3.여담: 막코딩하다보니 return NULL; 해놓고 바로아래 int형으로 리턴을 적어뒀더라....

warning: pointer targets in passing argument 2 of 'sprintf' differ in signedness
1.발생 이유: sprintf라는 함수를 사용하는 데 안에 들어가는 아규먼트(파라미터?)가 부호값을 상실했네
 sprintf(char * a, const char *b , ....) 뭐 이런식인데 sprintf(char * a,const u_int8_t *b , ....) 
이렇게 넣은거
2.해결방법 : 변수를 바로 쑤셔박지말고 sprintf(받는놈 , " % 자료형형형",  *b) 요런식으로 바끄야할듯

warning: type defaults to 'int' in declaration of '함수명'
1.발생 이유: 필자는 extern 함수 여기서 에러가 났엇다. 함수 원형은 int형인데 왜 int 안적냐는 워닝
2.해결방법: 컴파일러가 모르게 extern int 함수 이렇게 바꾸고 모르는척 컴파일다시하자

warning: case label value exceeds maximum value for type

1.발생 이유: switch 비교문에서 case 가 음수로 가는 경우
2.해결방법: 음수 비교를 하지 말거나, 나는 음수를 안쓴다 싶으면 unsigned를 넣든지


계속 추가할 계획이다. 시간남을때..





2014년 6월 20일 금요일

notepad++ MIB plugin 노트패드++ snmp 플러그인

심심해서 만들어 봤어요.

사용자 지정에서 입맛에 맞게 바꿔 쓰세요.

아래 내용을 복사한 뒤 mib.xml로 저장하여 사용.

파일 업로드가 안되네요.

<NotepadPlus>
   <UserLang name="MIB" ext="MIB" udlVersion="2.1">
       <Settings>
           <Global caseIgnored="yes" allowFoldOfComments="no" foldCompact="yes" forcePureLC="0" decimalSeparator="0" />
           <Prefix Keywords1="no" Keywords2="no" Keywords3="no" Keywords4="no" Keywords5="no" Keywords6="no" Keywords7="no" Keywords8="no" />
       </Settings>
       <KeywordLists>
           <Keywords name="Comments"></Keywords>
           <Keywords name="Numbers, prefix1"></Keywords>
           <Keywords name="Numbers, prefix2"></Keywords>
           <Keywords name="Numbers, extras1"></Keywords>
           <Keywords name="Numbers, extras2"></Keywords>
           <Keywords name="Numbers, suffix1"></Keywords>
           <Keywords name="Numbers, suffix2"></Keywords>
           <Keywords name="Numbers, range"></Keywords>
           <Keywords name="Operators1"></Keywords>
           <Keywords name="Operators2"></Keywords>
           <Keywords name="Folders in code1, open"></Keywords>
           <Keywords name="Folders in code1, middle"></Keywords>
           <Keywords name="Folders in code1, close"></Keywords>
           <Keywords name="Folders in code2, open"></Keywords>
           <Keywords name="Folders in code2, middle"></Keywords>
           <Keywords name="Folders in code2, close"></Keywords>
           <Keywords name="Folders in comment, open"></Keywords>
           <Keywords name="Folders in comment, middle"></Keywords>
           <Keywords name="Folders in comment, close"></Keywords>
           <Keywords name="Keywords1">OBJECT-TYPE</Keywords>
           <Keywords name="Keywords2"></Keywords>
           <Keywords name="Keywords3"></Keywords>
           <Keywords name="Keywords4"></Keywords>
           <Keywords name="Keywords5"></Keywords>
           <Keywords name="Keywords6"></Keywords>
           <Keywords name="Keywords7"></Keywords>
           <Keywords name="Keywords8"></Keywords>
           <Keywords name="Delimiters"></Keywords>
       </KeywordLists>
       <Styles>
           <WordsStyle name="DEFAULT" fgColor="000000" bgColor="FFFFFF" fontName="@Bitstream Vera Sans Mono" fontStyle="0" fontSize="10" nesting="0" />
           <WordsStyle name="COMMENTS" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
           <WordsStyle name="LINE COMMENTS" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
           <WordsStyle name="NUMBERS" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
           <WordsStyle name="KEYWORDS1" fgColor="FF8080" bgColor="FFFFFF" fontName="@Bitstream Vera Sans Mono" fontStyle="1" fontSize="12" nesting="0" />
           <WordsStyle name="KEYWORDS2" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
           <WordsStyle name="KEYWORDS3" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
           <WordsStyle name="KEYWORDS4" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
           <WordsStyle name="KEYWORDS5" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
           <WordsStyle name="KEYWORDS6" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
           <WordsStyle name="KEYWORDS7" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
           <WordsStyle name="KEYWORDS8" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
           <WordsStyle name="OPERATORS" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
           <WordsStyle name="FOLDER IN CODE1" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
           <WordsStyle name="FOLDER IN CODE2" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
           <WordsStyle name="FOLDER IN COMMENT" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
           <WordsStyle name="DELIMITERS1" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
           <WordsStyle name="DELIMITERS2" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
           <WordsStyle name="DELIMITERS3" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
           <WordsStyle name="DELIMITERS4" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
           <WordsStyle name="DELIMITERS5" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
           <WordsStyle name="DELIMITERS6" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
           <WordsStyle name="DELIMITERS7" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
           <WordsStyle name="DELIMITERS8" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
       </Styles>
   </UserLang>
</NotepadPlus>