알수없는 에러….

 컴파일중 이상한 오류를 발견했다..

/usr/local/arm/arm-linux/sys-include/asm/fcntl.h:74: parse error before “pid_t”
/usr/local/arm/arm-linux/sys-include/asm/fcntl.h:80: parse error before “loff_t”
/usr/local/arm/arm-linux/sys-include/asm/fcntl.h:82: parse error before “l_pid”

 단순한 프로그램이었는데…이상했다.

 이렇게도 바꾸고 저렇게도 바꾸어서 원인을 찾았는데…

 답은 헤더 파일의 입력 순서에 있었다.

 원래는..

#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>
#include <asm/fcntl.h>
#include <stdio.h>

였는데…

이를 다음과 같이 바꾸니 문제가 해결되었다..

#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>
#include <asm/fcntl.h>
#include <stdio.h>

 개운하지가 않다.

 문제는 해결했는데 어찌 해결했는지를 모르겠다….

 분명 헤더파일의 입력때문에 뭔가가 엉킨것 같은데….꼭 집어내지를 못하겠다.

 

wrong # args: should be “for start test next command”

 Tcl/Tk 스크립트를 실행시키는 도중 에러메시지를 발견했다.

wrong # args: should be “for start test next command”
    while executing
“for {set k 0} {$i < $opt(nn)} {incr i}”
    (file “wireless2.tcl” line 163)

 무슨 내용일까…

 구글을 살펴 보았으나 이렇다 할 내용은 찾지 못했다…

 그러다가….정말 어이없는 실수가 눈에 들어왔다.

 이 구문이 말썽이었는데…

for {set i} {$i < $opt(nn)} {incr i}

 다음과 같이 바꿔 주었다.

for {set i} {$i < $opt(nn)} {incr i} {


 차이점을 알겠는가? 바로 마지막 중광호를 열고 안열고의 차이였다.

 C언어에서라면 금방 잡아 냈을 오류인데…이렇게 사용하는 언어가 다르니 에러메시지가 나타내는 뜻조차도 제대로 파악하지 못하고 있었다….

 반성하자…

error: multiple types in one declaration

 g++ 컴파일 중 다음과 같은 에러 메시지를 확인했다.

 error: multiple types in one declaration

 위와 같은 메시지가 발생하는 이유는 간단하다

 클래스나 구조체의 마지막에 세미콜론을 잊어 버려서 생기는 에러이다. 생각보다 간단하다.

 하지만 이 세미콜론을 잊어버린 곳 찾기가 가끔은 쉽지 않을 경우가 있다. (…나처럼)

^M 없애는 방법

 윈도우에서의 파일을 리눅스에서 열때…

 CR LF 부분에 ^M 표시가 나는 경우가 있다.
 

나는바보다^M 그렇니까 이것도 못하지^M 바부팅

  이럴 때는 다음과 같이 입력해 주면 된다.

%s/^M/^M/g (여기서 ^M은 Ctrl+V <ENTER>로 입력합니다.)

  혹은 이렇게도 가능하다.

:set fileformat=unix
:set fileformat=dos
:set fileformat=mac

  더 많은 해결책을 찾고 싶다면 다음 링크를 참고하면 된다.

 관련 링크 : http://kldp.org/node/36998

윈도우 네트워크 프로그래밍 중 발생한 warning C4761

 윈도우에서 네트워크 프로그램 소스를 컴파일 하던 중 이상한 warning 을 발견하였다.


C:Documents and SettingsOwnerMy DocumentsNetworkhelloworld_client_winhelloworld_client_win.c(34) : warning C4761: integral size mismatch in argument; conversion supplied
 문제의 소스 부분은 다음이었다.

servAddr.sin_port = htons(atoi(argv[2]));
 보기에는 문제가 없는 부분이다. 정상작동하는 소스였다.(..리눅스에서 확인)

 물론 warning 을 무시하고 링크를 하여도 문제없이 프로그램을 잘 실행되었다.

 그렇다면 무엇이 문제일까….먼저 C4761 에 관한 내용을 찾아 보았다.

 다음과 같은 내용을 찾을 수 있었다.



Compiler Warning (level 1) C4761

integral size mismatch in argument : conversion supplied


The base types of the actual and formal parameters of a function were different.


The compiler converted the actual parameter to the type of the formal parameter.

 관련 링크 : http://msdn2.microsoft.com/en-us/library/aa733937(VS.60).aspx

 내용인즉 인자의 사이즈가 맞지 않는다는 것이다.

 다시 소스를 살펴보다가 다음을 발견하였다.


unsigned short__cdecl htons(unsigned short)
 즉 인자값으로 short 형이 와야 하는 것이다. 하지만 atoi() 함수는 리턴형이 int 값이므로 여기서 형변환의 문제가 생긴 것이다.

 다음과 같이 고쳐주니 warning 이 사라지고 깔끔한 컴파일이 되었다.


servAddr.sin_port = htons((unsigned short)atoi(argv[2]));