SW 개발

ADS / RVCT / 형변환 오류..

. . . 2010. 8. 10. 10:08
반응형

RVCT 로 컴파일하던도중에 char를 const char로 변환할수없다는 error 메시지가 뿌리면서 컴파일이 멈추는 증상이 발생한다. 특히 str 관련 함수의 경우 인자를 받을때 대부분 char 형으로 넘긴 인자를 const char로 변환해서 쓰는데.. 매번 충돌이 발생하였다!!

일단 ARM 홈페이지에서 퍼온내용..

http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0495a/BABDJCCI.html

 a value of type <type> cannot be used to initialize an entity of type <type>
The initializing string for a fixed size character array is exactly as long as the array size, leaving no room for a terminating \0, for example:

char name[5] = "Hello";
The name array can hold up to 5 characters. "Hello" does not fit because C strings are always null-terminated (for example, "Hello\0"). The compiler reports:

Error: #144: a value of type "const char [6]" cannot be used to initialize an entity of type "char [5]"
A similar error is also raised if there is an implicit cast of non-zero int to pointer.

For example:

void foo_func( void )
{
  char *foo=1;
}
results in the message:

#144: a value of type "int" cannot be used to initialize an entity of type "char *"
For the cast, this error can be suppressed with the use of the --loose_implicit_cast switch.







원래는 형변환 error code 가 #146 이지만... --loose_implicit_cast 옵션으로 해결이 가능한것 같다.

--loose_implicit_cast 옵션에 관한설명
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0348bk/CHDEJEEI.html
 

2.1.103. --loose_implicit_cast

이 옵션은 0이 아닌 정수를 포인터로 캐스트하는 암시적 캐스트와 같이 잘못된 암시적 캐스트를 올바른 캐스트로 만듭니다.

예제

int *p = 0x8000;

--loose_implicit_cast 옵션을 사용하지 않고 이 예제를 컴파일하면 오류가 생성됩니다.

--loose_implicit_cast 옵션을 사용하여 이 예제를 컴파일하면 표시되지 않도록 할 수 있는 경고 메시지가 생성됩니다.


일단 이 옵션으로 해당 error를 skip 가능한듯..
반응형