[请问]visual C++ 2005 中的malloc函数有关问题
[请教]visual C++ 2005 中的malloc函数问题
使用VC++2005编译C程序,出现错误 “非法间接寻址”在
句子S.base=(ElemType*)malloc(STACK_INIT_SIZE*sizeof(ElemType));中,(如果改成S.base=(ElemType*)malloc(sizeof(ElemType));就可通过编译。)
程序如下
#include "stdafx.h "
#define STACK_INIT_SIZE 100;
#define STACKINCREMENT 10;
#define OVERFLOW -2;
#define OK 1;
#define ERROR 0;
typedef int Status;
typedef struct{
int data;
}ElemType;
typedef struct SqStack{
ElemType *base;
ElemType *top;
int stacksize;
}SqStack;
Status InitStack(SqStack &S)
{
S.base=(ElemType*)malloc(STACK_INIT_SIZE*sizeof(ElemType));
if(!S.base)
return OVERFLOW;
S.top=S.base;
S.stacksize=STACK_INIT_SIZE;
return OK;
}//InitStack
。。。。。。。
实在找不出是什么问题,请高手指点
------解决方案--------------------
#define STACK_INIT_SIZE 100;
#define STACKINCREMENT 10;
#define OVERFLOW -2;
#define OK 1;
#define ERROR 0; 大哥,在用#define 的时候不需要后面的分号,C的基本语法,你把后面的所有分号去掉就OK了
------解决方案--------------------
管理
使用VC++2005编译C程序,出现错误 “非法间接寻址”在
句子S.base=(ElemType*)malloc(STACK_INIT_SIZE*sizeof(ElemType));中,(如果改成S.base=(ElemType*)malloc(sizeof(ElemType));就可通过编译。)
程序如下
#include "stdafx.h "
#define STACK_INIT_SIZE 100;
#define STACKINCREMENT 10;
#define OVERFLOW -2;
#define OK 1;
#define ERROR 0;
typedef int Status;
typedef struct{
int data;
}ElemType;
typedef struct SqStack{
ElemType *base;
ElemType *top;
int stacksize;
}SqStack;
Status InitStack(SqStack &S)
{
S.base=(ElemType*)malloc(STACK_INIT_SIZE*sizeof(ElemType));
if(!S.base)
return OVERFLOW;
S.top=S.base;
S.stacksize=STACK_INIT_SIZE;
return OK;
}//InitStack
。。。。。。。
实在找不出是什么问题,请高手指点
------解决方案--------------------
#define STACK_INIT_SIZE 100;
#define STACKINCREMENT 10;
#define OVERFLOW -2;
#define OK 1;
#define ERROR 0; 大哥,在用#define 的时候不需要后面的分号,C的基本语法,你把后面的所有分号去掉就OK了
------解决方案--------------------
管理