lcc.net 컴파일 중의 에러 ㄷ(도와주세여)

hys545의 이미지

cc -c -o /home/hys545/tmp/1/thunks.e lib/thunks.c
lib/thunks.c: In function `newthunk':
lib/thunks.c:33: error: invalid operands to binary -

File attachments: 
첨부파일 크기
파일 thunks.c2.02 KB
kane의 이미지

33c33
<       *(int *)(tp->code + offset) = (unsigned char *)f - (tp->code + offset + 4);
---
>       *(int *)(tp->code + offset) = (char *)f - (tp->code + offset + 4);
를 하시거나
33c33
<       *(int *)(tp->code + offset) = (char *)f - ((char *)tp->code + offset + 4);
---
>       *(int *)(tp->code + offset) = (char *)f - (tp->code + offset + 4);
를 하셔야 겠습니다.
25c25
<       struct thunk *tp = malloc(sizeof tp);
---
>       struct thunk *tp = malloc(sizeof *tp);
덧붙여서 이것도 해주셔야 할 듯.

아래는 포인터 연산과 관련하여 TCPL에서 발췌한 내용입니다.

Quote:
TCPL page 103.

The valid pointer operations are assignment of pointers of the same type, adding or subtracting a pointer and an integer, subtracting or comparing two pointers to members of the same array, and assigning or comparing to zero.

doldori의 이미지

kane wrote:
25c25
<       struct thunk *tp = malloc(sizeof tp);
---
>       struct thunk *tp = malloc(sizeof *tp);
덧붙여서 이것도 해주셔야 할 듯.

그렇지는 않을 겁니다.
malloc(sizeof tp)는 malloc(sizeof(struct thunk*))
malloc(sizeof *tp)는 malloc(sizeof(struct thunk)),
와 같습니다.
kane의 이미지

그렇군요. '*'만 보고 포인터라고 생각했습니다. :oops: