switch语句: 编译错误case label does not reduce to an integer constant

1、switch语句: 编译错误case label does not reduce to an integer constant

在case中肯定不能进行条件判断.
用嵌套的if else 就解决了

 

switch语句的格式为
switch(表达式)
{
  case 常量表达式1:  语句1
  case 常量表达式2:  语句2
  ^^^^^
  case 常量表达式n:  语句n
  default:          语句n+1
}

2、atoi: warning: passing arg 1 of `atoi' makes pointer from integer without a cast

make pointer from integer without a cast 的意思是:使指针指向一个整数型数据缺少一个指向
  这类问题大多是函数原参数指定是一个int整型的变量
    但是调用时却变成了其他类型的变量了,比如字符型
   这时要改变参数类型,至少也要做个强制类型转换。

 

3、`O_CREAT' undeclared (first use in this function)

man open 然后加上头文件解决

       #include <sys/types.h>
       #include <sys/stat.h>
       #include <fcntl.h>

4、warning: implicit declaration of function `close'

man close

#include <unistd.h>

5、 可能和sprintf有关

#include<stdio.h>
#include<string.h>

6、comparison is always true due to limited range of data type

   警告原因:有可能你定义了unsigned int uParam;但是你去做了if(uparam<0)的判断,

因为unsigned int 型的数据总是>=0的,因此这样的比较由于数据类型限制了它的范围,因此也就给出了警告。

 解决方法:可以去掉这样的判断。

posted on 2014-07-14 17:05  flying06  阅读(16435)  评论(0编辑  收藏  举报