동적할당 질문

한세희의 이미지

/*
*스택구현
*/

#include

int *Stack;
int push;
int pop;

void Momory_Assign(int Momory_Size); //사용자로부터 받는값만큼 메모리를 할당한다.

int main(void)

{
int User_Num;

printf("Enter Size of Memory:");
scanf("%d", &User_Num);

Momory_Assign(User_Num);



}

void Momory_Assign(int Momory_Size)
{
Stack = (int*)malloc(sizeof(int)*Momory_Size);

}

인데 컴파일 하면

--------------------Configuration: M - Win32 Debug--------------------
Compiling...
M.C
C:\Program Files\Microsoft Visual Studio\MyProjects\M\M.C(29) : warning C4013: 'malloc' undefined; assuming extern returning int

이렇게 warning이 뜨네요....잘못한거 없는거 같은데....이유가 뭐에요?

임종규의 이미지

stdlib.h 를 include 하셔야 합니다. malloc 함수를 사용하시려면...

#include <stdlib.h>

/* How to Love Others */
while(GetDepth(Love) < Enough) DoLove();

hey의 이미지

malloc()이 뭔지 모른다는 겁니다. 그래서 반환값을 알 수 없으므로 int로 간주하겠다는 겁니다.
필요한 헤더를 include 하세요

May the F/OSS be with you..



----------------------------
May the F/OSS be with you..