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的,因此這樣的比較由於數據類型限制了它的范圍,因此也就給出了警告。

 解決方法:可以去掉這樣的判斷。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM