메모리 write ?? warning ...좀 찾아주세요
글쓴이: chxooi / 작성시간: 일, 2010/06/06 - 8:57오전
메모리 버퍼 디바이스 드라이버 작성중인데요
에러가나는데 원인을 모르겠네요...
ssize_t ram_read(uint32_t partition_id, char * buf, size_t count, loff_t offset) { #if 1/*test*/ copy_to_user(buf,memory_buffer,1); /* Changing reading position as best suits */ if (offset == 0) { offset=1; return 1; } else { return 0; } #endif return count; } ssize_t ram_write( uint32_t partition_id, const char * buf, size_t count, loff_t offset) { #if 1 char *tmp; tmp=buf+count-1; copy_from_user(memory_buffer,tmp,1); return 1; #endif return count; }
에러가 나는 부분은
tmp=buf+count-1 이부분인데 Error 는 아니고 Warning 으로 나오네요...
:148: warning: assignment discards qualifiers from pointer target type
뭐가 잘못된걸까요???
참고한 코드는
http://www.joinc.co.kr/modules/moniwiki/wiki.php/Site/Embedded/Documents/WritingDeviceDriversInLinux
여기서 가지고 왔습니다.
Forums:
buf 는 const char *, 즉
buf 는 const char *, 즉 상수 포인터형입니다.
그리고 tmp 는 그냥 char * 형이고요.
아마, buf 와 tmp 의 형이 달라고 그런 경고가 떴을 겁니다.
tmp = (char *)buf+count-1;
로 해주면 아마(자신은 없네요....) 경고는 제거될 겁니다.
어떤 컴파일러
어떤 컴파일러 옵션을 쓰냐에 따라서 위 내용이 맞을 수도 틀릴 수도 있습니다. const char *를 char * 로 강제 변환하여도 다른 경고가 날 듯 합니다. 차라리 함수 인자 자체를 char * 로 변경을 하는게 좋을 듯 합니다.
음...
char *tmp; 를 const char *tmp; 로 바꿔주시는게 맞겠네요.
const 로 넘어온 얘는 중간에 const 가 보장되도록 코드를 작성하는 것이 좋습니다.
실질적으로 tmp 의 내용 변경없이 read-only 로 사용한다 하더라도..
문법상 const 로 한정한 변수들은 명시적으로 const 로 지정해 주는 것이 코딩 미스를 줄일 수 있습니다.
되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』
되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』
댓글 달기