c - 在 C 中实现 Stack 时出现奇怪的错误

标签 c compiler-errors stack

我试图在 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/

相关文章:

swift - 为什么这个函数给我一个 "Command Failed due to signal"错误?

javascript - 如何在 JavaScript 中实现堆栈和队列?

c++ - 运行时检查失败 #2 - 变量周围的堆栈已损坏 C++

c - 从堆栈内存中删除结构

c - 如何使用 dentry_path_raw()

c - 在 C 中存储日期然后输出到 csv 文件的最佳数据类型是什么?

c++ - 有人可以解释 malloc(20 * c | -(20 * (unsigned __int64)(unsigned int)c >> 32 != 0)) 的含义

c - C 语言的基本插入排序算法(TDM-GCC 编译器)

vector - Borland C++ Builder 6 - E2316 'vector' 不是 'std' 的成员

c++ - 无法识别的命令行选项 '-std=c++11'