c++ malloc 问题

来源:百度知道 编辑:UC知道 时间:2024/05/19 20:58:49
那个老大帮忙下
#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
typedef int Status;
typedef int SElemType;
typedef struct{
SElemType *base;
SElemType *top;
int stacksize;
}SqStack;
Status InitStack(SqStack &s)
{
s.base=(SElemType *)malloc(STACK_INIT_SIZE*sizeof(SElemType));
if(NULL==s.base)
exit(OVERFLOW);
s.top=s.base;
s.stacksize=STACK_INIT_SIZE;
return OK;
}//InitStack

这只是一部分,编译的时候老报错
syntax error : missing ')' before ';'
syntax error : ')'
illegal indirection
执行 cl.exe 时出错.

就是malloc那一行有错误,还有用到realloc的时候也是错,那位老大帮看下啊先谢了

不是malloc这儿错了
是exit(OVERFLOW); 这儿错了

你去看一下你的OVERFLOW的定义是不是这样定义的
#define OVERFLOW 0;
如果是改一下不要逗号
我就是老爱出这样的错

你打CMD试试

-_-!

LS说得对,但LZ的问题应该是#define STACK_INIT_SIZE 10后面多了个分号,如下
---------------------------

#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
typedef int Status;
typedef int SElemType;
#define STACK_INIT_SIZE 10;//这里多了个分号
#define OVERFLOW 0
#define OK 0
typedef struct{
SElemType *base;
SElemType *top;
int stacksize;
}SqStack;
Status InitStack(SqStack &s)
{
s.base=(SElemType *)malloc(STACK_INIT_SIZE*sizeof(SElemType));
if(NULL==s.base)
exit(OVERFLOW);
s.top=s.base;
s.stacksize=STACK_INIT_SIZE;
return OK;
}//InitStack
main()
{
}

#include <iostream>

typedef int Status;
typedef int SElemT