이렇게 많이 게시 되었기 때문에 게시하는 것이 싫지만 그 중 아무 것도 내가 보는 것을 처리하지 못하는 것 같습니다. 정상적인 문제 (선언되지 않은 함수, 의도하지 않은 캐스트, 기본 포인터의 오해)는 여기에 적용되지 않습니다. 이것은 내 코드의 버려진 버전입니다.포인터에 포인터를 할당 할 때 경고 메시지가 나타납니다. 할당은 포인터에서 정수를 만듭니다.
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
extern void* malloc (size_t size);
typedef struct {
size_t size;
uint8_t* buffer, curr, next;
} buffer_t;
void init(buffer_t* b, int size) {
b->size = (size_t) size;
b->buffer = (uint8_t*) malloc(sizeof(uint8_t) * b->size + 1);
b->curr = (uint8_t*) b->buffer; // warning: assignment makes integer from pointer without a cast [enabled by default]
b->next = (uint8_t*) b->buffer; // warning: assignment makes integer from pointer without a cast [enabled by default]
}
int main (int argc, char* argv[]) {
buffer_t buf;
init(&buf, 16);
return 0;
}
이것은 캐스트가 없어도 실패하지만, 더 명확하게 나타납니다.
저는 MinGW/MSYS에서 gcc 4.7.2로 WinXP (예, 예, 예)로 컴파일하고 있습니다. 다음 명령을 사용하십시오 :
gcc -std=c99 -Wall -o testing test.c
어떤 도움이 필요합니까?
'malloc'은 ''에 선언되어 있습니다. 왜 그걸 너 혼자 선언하니? (그건 당신의 문제와 관련이 없습니다.) –
또한 [당신은'malloc'에서 리턴 값을 던지면 안됩니다.] (http://stackoverflow.com/questions/605845/do-i-cast-the-result-of -malloc),'b-> buffer'를 이미'uint8_t *'로 캐스팅 할 필요가 없습니다. –