我试图在 C 中实现堆栈,但它在我的 MinGw 编译器中出现了奇怪的错误
gcc -Wall -o stack stack.c
堆栈.c
#include "stack.h"
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
Stack *create(int size) {
Stack *result;
result = (Stack *) malloc( sizeof(Stack) * size );
assert(result != NULL);
result -> file = result;
result -> maxAllocate = size;
result -> top = -1;
return result;
}
堆栈.h
#define MAX_SIZE 1024
typedef struct {
void **file;
int top;
int maxAllocate; // current size of array allocated for stack
} Stack;
Stack *create(int size);
int push(Stack *s, void *x);
void *pop(Stack *s);
int isEmpty(Stack *s);
错误
C:\test>gcc -Wall -o stack stack.c
stack.c: In function 'create':
stack.c:26:17: warning: assignment from incompatible pointer type [enabled by de
fault]
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../libmingw32.a(main.o): In function
`main':
C:\MinGW\msys\1.0\src\mingwrt/../mingw/main.c:73: undefined reference to `WinMai
n@16'
collect2: ld returned 1 exit status
最佳答案
使用 gcc -Wall -o stack stack.c
你只编译 stack.c
(其中有 o main 函数)但是对于一个正常运行的应用程序你也将需要一个 main
函数,作为主入口点:http://en.wikipedia.org/wiki/Entry_point
关于c - 在 C 中实现 Stack 时出现奇怪的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22351903/