谁能帮我把这警告去掉?
谁能帮我把这警告去掉?现在学数据结构,, 想写一个计算器,, 于是我就开始写...
但是才下手就发现有一个去不掉的警告....
三个文件: stack.h input.h cal.c
stack.h:
程序代码:
#include <stdio.h> #include <stdlib.h> #ifndef _STACK_H__ #define _STACK_H__ #define _STACK_INIT_SIZE_ 100 #define _STACK_PUSH_SIZE_ 10 typedef int elem; typedef struct stack{ void *base; void *top; int stacksize; }Stack; static inline void alloc_err(void) { fputs("Malloc Err\n", stderr); exit(-1); } static inline int re_malloc(Stack *S, int size) { void *tmp; tmp = realloc(S->base, size * (S->stacksize + _STACK_PUSH_SIZE_)); if(tmp == NULL){ alloc_err(); } S->base = tmp; S->top = S->base + S->stacksize; S->stacksize += _STACK_PUSH_SIZE_; return 1; } #define stack_init(S, type) do{\ type *tmp;\ tmp = malloc(sizeof(type) * _STACK_INIT_SIZE_); \ if(tmp == NULL){ \ alloc_err(); \ } \ S->base = S->top = tmp; \ S->stacksize = _STACK_INIT_SIZE_; \ }while(0); int inline stack_isempty(Stack *S) { return S->base == S->top ? 1 : 0; } //检查是否为空栈, 即base == top #define stack_gettop(S, type) do{ \ return *((type *)S->top); \ }while(0); //获取栈顶元素 #define stack_push(S, type, push) do{ \ if(((type *)S->top) - ((type *)S->base) == S->stacksize){ \ re_malloc(S, sizeof(type)); \ } \ *((type *)S->top)++ = push; \ }while(0); //将元素插入栈中 #define stack_pop(S, type, pop) do{\ if(pop == NULL){ \ --((type *)S->top); \ } \ *pop = *(--((type *)S->top)); \ }while(0); //出栈,, //返回栈的长度 #define stack_lenth(S, type) do{\ return ((type)S->top) - ((type)S->base);\ }while(0); //清空栈 void inline stack_clean(Stack *S) { S->top = S->base; } void inline stack_destory(Stack *S) { free(S->base); } #endif
input.h
程序代码:
#include <stdio.h> #ifndef _INPUT_H_ #define _INPUT_H_ typedef void *input_t; #define input_init(input_t) do{;}while(0); inline char input_getchar(void *input) { return getchar(); } #endif
cal.c
程序代码:
#include "input.h" #include "stack.h" void cal(void); int main(void) { while(1){ cal(); } return 0; } void cal(void) { Stack num, cha; input_t input; char ch; input_init(input); /*初始化各个结构*/ stack_init((&num), int); stack_init((&cha), char); stack_push((&cha), char, '#'); /*将结束的符号压入符号栈*/ ch = input_getchar(input); /*获取用户输入的字符*/ }
具体的警告是:
22 [Warning] use of cast expressions as lvalues is deprecated