선언 지정자에 둘 이상의 데이터 형식 오류가 있습니다.
저는 C가 처음입니다.
다음 오류가 발생합니다.
내장 함수 'malloc'의 호환되지 않는 암묵적 선언
다음과 같은 답변을 바탕으로 코드를 수정할 때도<stdlib.h>
, 아직도 알 수 있습니다.
선언 지정자의 두 가지 이상의 데이터 유형
이 작업을 수행할 때:
struct tnode
{
int data;
struct tnode * left;
struct tnode * right;
}
struct tnode * talloc(int data){
struct tnode * newTnode;
newTnode = (struct tnode *) malloc (sizeof(struct tnode));
newTnode->data = data;
newTnode->left = NULL;
newTnode->right = NULL;
return newTnode;
}
어떻게 고치죠?
당신이 넣어야 합니다.;
뒤에struct
선언:
struct tnode
{
int data;
struct tnode * left;
struct tnode * right;
}; // <-- here
원래 오류는 사용을 시도했기 때문입니다.malloc
포함하지 않고stdlib.h
.
새로운 오류(지금까지 다른 모든 답변을 무효화했기 때문에 실제로는 별도의 질문이어야 함)는 마지막에 세미콜론 문자가 없기 때문입니다.struct
정의.
이 코드는 정상적으로 컴파일됩니다(비록 a가 없어도).main
):
#include <stdlib.h>
struct tnode
{
int data;
struct tnode * left;
struct tnode * right;
};
struct tnode * talloc(int data){
struct tnode * newTnode;
newTnode = (struct tnode *) malloc (sizeof(struct tnode));
newTnode -> data = data;
newTnode -> left = NULL;
newTnode -> right = NULL;
return newTnode;
}
"묵시적 선언"은 공식적으로 선언되지 않은 기능을 사용하려고 하는 것을 의미합니다.
아마 잊어버리셨을 겁니다.#include <stdlib.h>
여기에는 다음에 대한 함수 선언이 포함됩니다.malloc
.
적절한 헤더 파일이 포함되어 있습니까?
즉, 당신의 파일 상단에 다음과 같은 줄이 있습니까?
#include <stdlib.h>
도움이 되길 바랍니다.
malloc()에 대한 정의가 들어 있는 헤더 파일을 포함했는지 확인합니다.
#include "stdlib.h"
언급URL : https://stackoverflow.com/questions/2098973/two-or-more-data-types-in-declaration-specifiers-error
'programing' 카테고리의 다른 글
레일/앵글 배포 시 알 수 없는 공급자 오류JS 앱에서 헤로쿠로 (0) | 2023.10.22 |
---|---|
어떻게 액시오스 요격기를 사용할 수 있습니까? (0) | 2023.10.22 |
MySQL에서 데이터를 저장하는 방법 (0) | 2023.10.22 |
연산자 문제 Oracle에 없음 (0) | 2023.10.22 |
LINQ에서 MySQL로 - 가장 좋은 옵션은 무엇입니까? (0) | 2023.10.22 |