C语言常见编译错误及分析

2023-05-16

目录

    • 绪论
    • 第一安装错误:
    • [1]Error spawning cl.exe
    • [2]fatal error C1083: Cannot open include file:
    • 第二打开编译器失败,提示不能打开
    • 第三cannot execute program解决方案
    • 第四连接Link.exe错误解决方案
    • 第五 error C2143: syntax error : missing ')' before 'return'解决方案
    • 第六涉及`scanf`输出结果为空的错误解决方案
    • 第七
    • error C2065: 'a' : undeclared identifier
    • error C2109: subscript requires array or pointer type
    • error C2102: '&' requires l-value
    • 第八
    • error C2018: unknown character '0xa3'
    • error C2018: unknown character '0xac'
    • 第九
    • fatal error C1083: Cannot open include file: 'stduio.h': No such file or directory
    • 文字说明
    • cannot open Debug/lalal.exe for writng executing link.exe.
    • fatal error C1003: error count exceeds number; stopping compilation
    • fatal error C1004: unexpected end of file found
    • fatal error C1083: Cannot open include file: ‘xxx’: No such file or directory
    • fatal error C1903: unable to recover from previous error(s); stopping compilation
    • error C2001: newline in constant
    • error C2006: #include expected a filename, found ‘identifier’
    • error C2007: #define syntax
    • error C2008: ‘xxx’ : unexpected in macro definition
    • error C2009: reuse of macro formal ‘identifier’
    • error C2010: ‘character’ : unexpected in macro formal parameter list
    • error C2014: preprocessor command must start as first nonwhite space
    • error C2015: too many characters in constant
    • error C2017: illegal escape sequence
    • error C2018: unknown character ‘0xhh’
    • error C2019: expected preprocessor directive, found ‘character’
    • *error C2021: expected exponent value, not ‘character’*
    • error C2039: ‘identifier1’ : is not a member of ‘identifier2’
    • error C2041: illegal digit ‘x’ for base ‘n’
    • error C2048: more than one default
    • error C2050: switch expression not integral
    • error C2051: case expression not constant
    • error C2052: ‘type’ : illegal type for case expression
    • error C2057: expected constant expression
    • error C2058: constant expression is not integral
    • error C2059: syntax error : ‘xxx’
    • error C2064: term does not evaluate to a function
    • error C2065: ‘xxx’ : undeclared identifier
    • error C2078: too many initializers
    • error C2082: redefinition of formal parameter ‘xxx’
    • error C2084: function ‘xxx’ already has a body
    • error C2086: ‘xxx’ : redefinition
    • error C2087: ‘’ : missing subscript
    • error C2100: illegal indirection
    • error C2105: ‘operator’ needs l-value
    • error C2296: ‘%’ : illegal, left operand has type ‘float’ error C2297: ‘%’ : illegal, right operand has type ‘float’
    • error C2371: ‘xxx’ : redefinition; different basic types
    • error C2440: ‘=’ : cannot convert from ‘char [2]’ to ‘char’
    • error C2447: missing function header (old-style formal list?) error C2448: ‘’ : function-style initializer appears to be a function definition
    • error C2450: switch expression of type ‘xxx’ is illegal
    • error C2466: cannot allocate an array of constant size 0
    • error C2601: ‘xxx’ : local function definitions are illegal
    • error C2632: ‘type1’ followed by ‘type2’ is illegal
    • error C2660: ‘xxx’ : function does not take n parameters
    • error C2664: ‘xxx’ : cannot convert parameter n from ‘type1’ to ‘type2’
    • error C2676: binary ‘<<’ : ‘class istream_withassign’ does not define this operator or a conversion to a type acceptable to the predefined operator error C2676: binary ‘>>’ : ‘class ostream_withassign’ does not define this operator or a conversion to a type acceptable to the predefined operator

绪论

首先我们来分类一下几种常见错误

  1. 逻辑错误
  2. 语法错误
  3. 链接错误
  4. 编译错误
  5. 安装错误

第一安装错误:


[1]Error spawning cl.exe

[2]fatal error C1083: Cannot open include file:

在这里插入图片描述
以上两种错误情况是一样的,头文件没有放到安装目录下,都是你在安装的时候路径选择错了,怎么解决呢?重新安装??这不能解决问题的!!!
解决方案:
在这里插入图片描述
在这里插入图片描述
我们首先点击可执行文件,然后在路径区将前四个路径分别做如下修改,和我下边的地址设置成一样!!如果你的前四个文件路径和我下边的不一样,那你就双击一下,修改地址即可。
在这里插入图片描述
双击之后点击那三个点就可以选择文件路径了!!
在这里插入图片描述
接下来目录选择头文件include区域!和上一步操作一样,把路径地址换成我下面的路径,记住如果这两你多余四行,那你就删除,删到只剩三行即可。
在这里插入图片描述
接下来选择目录如下,同时修改前两行地址,和下边的地址要一样,多余行数删除处理!
在这里插入图片描述
最后一步,选择另外一个目录,换掉前三行地址,和如下地址要一样!!
在这里插入图片描述
做完如上操作之后点击确定在进行编译,问题就解决了,如果没有解决那就是你的某个目录下的文件没有按照我的地址来配对,再检查一下就行了!

第二打开编译器失败,提示不能打开

在这里插入图片描述
这个问题的其实很简单的。解决方案:

  1. 点击进入---->下载该解压器
  2. 安装好之后,观察压缩包变成360zip之后就可以直接打开了!
    在这里插入图片描述

第三cannot execute program解决方案

在这里插入图片描述
问题导致原因:
你添加的工程名字和文件名字不一致
在这里插入图片描述
解决方案:
首先建好项目名字,在建你的C++source时,记得名字一定要一样!!!还有不能用中文名字!!
在这里插入图片描述
在这里插入图片描述

第四连接Link.exe错误解决方案

错误原因:
一个项目建了多个工程文件,且名字不对应,与第三错误类似

在这里插入图片描述
解决方案:重新新建一个项目,再建一个工程文件,记得名字要一样!!

第五 error C2143: syntax error : missing ‘)’ before 'return’解决方案

当发现这个语句的时候发现只要我们对应去找提示错误的语句就可以了,把失去的分号去掉就可以了!!!

在这里插入图片描述
可是我们发现,提示的语句是有分号的!!!
在这里插入图片描述
这个时候我们要去该语句的上一句或是下一句去寻找分号是否有缺失,双引号也是我们排查的目标!!!
在这里插入图片描述
我们发现其实上一个语句缺了分号
在这里插入图片描述
这个错误是很多人都容易忽略的,也是不容易看出来的,但一定要有这个思路!!

第六涉及scanf输出结果为空的错误解决方案

我们在输入一个值后输出缺为空!!
在这里插入图片描述
排查错误步骤:

  1. 输入语句格式【忘了地址符&】
  2. 输出语句格式【忘了逗号】
  3. 变量定义数据类型【数据类型不匹配】
    在这里插入图片描述
    加上地址符&之后就OK了

第七

error C2065: ‘a’ : undeclared identifier

error C2109: subscript requires array or pointer type

error C2102: ‘&’ requires l-value


在这里插入图片描述
分析:凡是发现连带错误的时候,都要自顶向下的检查拍错!看代码的时候也是自顶向下进行排查!
错误解决方案:
把for循环后边的分号去掉!!
在这里插入图片描述
你只要记住,也就是循环,选择结构的都不要再后边加分号。forif不要再后边加分号。

第八

error C2018: unknown character ‘0xa3’

error C2018: unknown character ‘0xac’

我相信这个错误大家已经见得司空见惯了吧!!!是不是一脸懵逼???
解决方案:
检查标点符号!检查标点符号!检查标点符号!

注意你的标点符号,有一个地方的标点用成了中文!!!
发现句子外边的分号正常那就看中间句子的空格间隙是不是特别大,如果大,那就说明符号有问题!!
在这里插入图片描述

第九

fatal error C1083: Cannot open include file: ‘stduio.h’: No such file or directory

这个是不是特别眼熟??
解决方案
观察头文件,你的头文件拼错了!!!
你们顺手就喜欢打一个u在上面,正确头文件:<stdio.h>
在这里插入图片描述


文字说明

cannot open Debug/lalal.exe for writng executing link.exe.

在这里插入图片描述
解决方案:
在这里插入图片描述

fatal error C1003: error count exceeds number; stopping compilation

中文对照:(编译错误)错误太多,停止编译
分析:修改之前的错误,再次编译

fatal error C1004: unexpected end of file found

中文对照:(编译错误)文件未结束
分析:一个函数或者一个结构定义缺少“}”、或者在一个函数调用或表达式中括号没有配对出现、或者注释符“/„/”不完整等

fatal error C1083: Cannot open include file: ‘xxx’: No such file or directory

中文对照:(编译错误)无法打开头文件xxx:没有这个文件或路径
分析:头文件不存在、或者头文件拼写错误、或者文件为只读

fatal error C1903: unable to recover from previous error(s); stopping compilation

中文对照:(编译错误)无法从之前的错误中恢复,停止编译
分析:引起错误的原因很多,建议先修改之前的错误

error C2001: newline in constant

中文对照:(编译错误)常量中创建新行
分析:字符串常量多行书写

error C2006: #include expected a filename, found ‘identifier’

中文对照:(编译错误)#include命令中需要文件名
分析:一般是头文件未用一对双引号或尖括号括起来,例如“#include stdio.h”

error C2007: #define syntax

中文对照:(编译错误)#define语法错误
分析:例如“#define”后缺少宏名,例如“#define”

error C2008: ‘xxx’ : unexpected in macro definition

中文对照:(编译错误)宏定义时出现了意外的xxx
分析:宏定义时宏名与替换串之间应有空格,例如“#define TRUE”1””

error C2009: reuse of macro formal ‘identifier’

中文对照:(编译错误)带参宏的形式参数重复使用
分析:宏定义如有参数不能重名,例如“#define s(a,a) (a*a)”中参数a重复

error C2010: ‘character’ : unexpected in macro formal parameter list

中文对照:(编译错误)带参宏的形式参数表中出现未知字符
分析:例如“#define s(r|) r*r”中参数多了一个字符‘|’

error C2014: preprocessor command must start as first nonwhite space

中文对照:(编译错误)预处理命令前面只允许空格
分析:每一条预处理命令都应独占一行,不应出现其他非空格字符

error C2015: too many characters in constant

中文对照:(编译错误)常量中包含多个字符
分析:字符型常量的单引号中只能有一个字符,或是以“\”开始的一个转义字符,例如“char error = ‘error’;”

error C2017: illegal escape sequence

中文对照:(编译错误)转义字符非法
分析:一般是转义字符位于 ’ ’ 或 ” ” 之外,例如“char error = ’ ‘\n;”

error C2018: unknown character ‘0xhh’

中文对照:(编译错误)未知的字符0xhh
分析:一般是输入了中文标点符号,例如“char error = ‘E’;”中“;”为中文标点符号

error C2019: expected preprocessor directive, found ‘character’

中文对照:(编译错误)期待预处理命令,但有无效字符
分析:一般是预处理命令的#号后误输入其他无效字符,例如“#!define TRUE 1”

error C2021: expected exponent value, not ‘character’

中文对照:(编译错误)期待指数值,不能是字符
分析:一般是浮点数的指数表示形式有误,例如123.456E

error C2039: ‘identifier1’ : is not a member of ‘identifier2’

中文对照:(编译错误)标识符1不是标识符2的成员
分析:程序错误地调用或引用结构体、共用体、类的成员

error C2041: illegal digit ‘x’ for base ‘n’

中文对照:(编译错误)对于n进制来说数字x非法
分析:一般是八进制或十六进制数表示错误,例如“int i = 081;”语句中数字‘8’不是八进制的基数

error C2048: more than one default

中文对照:(编译错误)default语句多于一个
分析:switch语句中只能有一个default,删去多余的default

error C2050: switch expression not integral

中文对照:(编译错误)switch表达式不是整型的
分析:switch表达式必须是整型(或字符型),例如“switch (“a”)”中表达式为字符串,这是非法的

error C2051: case expression not constant

中文对照:(编译错误)case表达式不是常量
分析:case表达式应为常量表达式,例如“case “a””中“”a””为字符串,这是非法的

error C2052: ‘type’ : illegal type for case expression

中文对照:(编译错误)case表达式类型非法
分析:case表达式必须是一个整型常量(包括字符型)

error C2057: expected constant expression

中文对照:(编译错误)期待常量表达式
分析:一般是定义数组时数组长度为变量,例如“int n=10; int a[n];”中n为变量,这是非法的

error C2058: constant expression is not integral

中文对照:(编译错误)常量表达式不是整数
分析:一般是定义数组时数组长度不是整型常量

error C2059: syntax error : ‘xxx’

中文对照:(编译错误)‘xxx’语法错误
分析:引起错误的原因很多,可能多加或少加了符号xxx

error C2064: term does not evaluate to a function

中文对照:(编译错误)无法识别函数语言
分析:(1)函数参数有误,表达式可能不正确,例如“sqrt(s(s-a)(s-b)(s-c));”中表达式不正确(2)变量与函数重名或该标识符不是函数,例如“int i,j; j=i();”中i不是函数

error C2065: ‘xxx’ : undeclared identifier

中文对照:(编译错误)未定义的标识符xxx
分析:(1)如果xxx为cout、cin、scanf、printf、sqrt等,则程序中包含头文件有误(2)未定义变量、数组、函数原型等,注意拼写错误或区分大小写

error C2078: too many initializers

中文对照:(编译错误)初始值过多
分析:一般是数组初始化时初始值的个数大于数组长度,例如“int b[2]={1,2,3};”

error C2082: redefinition of formal parameter ‘xxx’

中文对照:(编译错误)重复定义形式参数xxx
分析:函数首部中的形式参数不能在函数体中再次被定义

error C2084: function ‘xxx’ already has a body

中文对照:(编译错误)已定义函数xxx
分析:在VC++早期版本中函数不能重名,6.0版本中支持函数的重载,函数名可以相同但参数不一样

error C2086: ‘xxx’ : redefinition

中文对照:(编译错误)标识符xxx重定义
分析:变量名、数组名重名

error C2087: ‘’ : missing subscript

中文对照:(编译错误)下标未知
分析:一般是定义二维数组时未指定第二维的长度,例如“int a[3][];”

error C2100: illegal indirection

中文对照:(编译错误)非法的间接访问运算符“
分析:对非指针变量使用“
”运算

error C2105: ‘operator’ needs l-value

中文对照:(编译错误)操作符需要左值
分析:例如“(a+b)++;”语句,“++”运算符无效

error C2296: ‘%’ : illegal, left operand has type ‘float’ error C2297: ‘%’ : illegal, right operand has type ‘float’

中文对照:(编译错误)%运算的左(右)操作数类型为float,这是非法的 
分析:求余运算的对象必须均为int类型,应正确定义变量类型或使用强制类型转换

error C2371: ‘xxx’ : redefinition; different basic types

中文对照:(编译错误)标识符xxx重定义;基类型不同
分析:定义变量、数组等时重名

error C2440: ‘=’ : cannot convert from ‘char [2]’ to ‘char’

中文对照:(编译错误)赋值运算,无法从字符数组转换为字符
分析:不能用字符串或字符数组对字符型数据赋值,更一般的情况,类型无法转换

error C2447: missing function header (old-style formal list?) error C2448: ‘’ : function-style initializer appears to be a function definition

中文对照:(编译错误)缺少函数标题(是否是老式的形式表?) 
分析:函数定义不正确,函数首部的“( )”后多了分号或者采用了老式的C语言的形参表

error C2450: switch expression of type ‘xxx’ is illegal

中文对照:(编译错误)switch表达式为非法的xxx类型
分析:switch表达式类型应为int或char

error C2466: cannot allocate an array of constant size 0

中文对照:(编译错误)不能分配长度为0的数组
分析:一般是定义数组时数组长度为0

error C2601: ‘xxx’ : local function definitions are illegal

中文对照:(编译错误)函数xxx定义非法
分析:一般是在一个函数的函数体中定义另一个函数

error C2632: ‘type1’ followed by ‘type2’ is illegal

中文对照:(编译错误)类型1后紧接着类型2,这是非法的
分析:例如“int float i;”语句

error C2660: ‘xxx’ : function does not take n parameters

中文对照:(编译错误)函数xxx不能带n个参数
分析:调用函数时实参个数不对,例如“sin(x,y);”

error C2664: ‘xxx’ : cannot convert parameter n from ‘type1’ to ‘type2’

中文对照:(编译错误)函数xxx不能将第n个参数从类型1转换为类型2
分析:一般是函数调用时实参与形参类型不一致

error C2676: binary ‘<<’ : ‘class istream_withassign’ does not define this operator or a conversion to a type acceptable to the predefined operator error C2676: binary ‘>>’ : ‘class ostream_withassign’ does not define this operator or a conversion to a type acceptable to the predefined operator

分析:“>>”、“<<”运算符使用错误,例如“cin<

C语言常见编译错误及分析

      • 1、fatal error C1003: error count exceeds number; stopping compilation
      • 2、fatal error C1004: unexpected end of file found
      • 3、fatal error C1083: Cannot open include file: 'xxx': No such file or directory
      • 4、fatal error C1903: unable to recover from previous error(s); stopping compilation
      • 5、error C2001: newline in constant
      • 6、error C2006: #include expected a filename, found 'identifier'
      • 7、error C2007: #define syntax
      • 8、error C2008: 'xxx' : unexpected in macro definition
      • 9、error C2009: reuse of macro formal 'identifier'
      • 10、error C2010: 'character' : unexpected in macro formal parameter list
      • 11、error C2014: preprocessor command must start as first nonwhite space
      • 12、error C2015: too many characters in constant
      • 13、error C2017: illegal escape sequence
      • 14、error C2018: unknown character '0xhh'
      • 15、error C2019: expected preprocessor directive, found 'character'
      • 16、error C2021: expected exponent value, not 'character'
      • 17、error C2039: 'identifier1' : is not a member of 'identifier2'
      • 18、error C2041: illegal digit 'x' for base 'n'
      • 19、error C2048: more than one default
      • 20、error C2050: switch expression not integral
      • 21、error C2051: case expression not constant
      • 22、error C2052: 'type' : illegal type for case expression
      • 23、error C2057: expected constant expression
      • 24、error C2058: constant expression is not integral
      • 25、error C2059: syntax error : 'xxx'
      • 26、error C2064: term does not evaluate to a function
      • 27、error C2065: 'xxx' : undeclared identifier
      • 28、error C2078: too many initializers
      • 29、error C2082: redefinition of formal parameter 'xxx'
      • 30、error C2084: function 'xxx' already has a body
      • 31、error C2086: 'xxx' : redefinition
      • 32、error C2087: '' : missing subscript
      • 33、error C2100: illegal indirection
      • 34、error C2105: 'operator' needs l-value
      • 35、error C2106: 'operator': left operand must be l-value
      • 36、error C2110: cannot add two pointers
      • 37、error C2117: 'xxx' : array bounds overflow
      • 38、error C2118: negative subscript or subscript is too large
      • 39、error C2133: 'xxx' : unknown size
      • 40、error C2137: empty character constant。
      • 41、error C2143: syntax error : missing 'token1' before 'token2'
      • 42、error C2146: syntax 4error : missing 'token1' before identifier 'identifier'
      • 43、error C2144: syntax error : missing ')' before type 'xxx'
      • 44、error C2181: illegal else without matching if
      • 45、error C2196: case value '0' already used
      • 46、error C2296: '%' : illegal, left operand has type 'float'
      • 47 error C2297: '%' : illegal, right operand has type 'float'
      • 48、error C2371: 'xxx' : redefinition; different basic types
      • 49、error C2440: '=' : cannot convert from 'char [2]' to 'char'
      • 50、error C2447: missing function header (old-style formal list?)
      • 51、error C2448: '' : function-style initializer appears to be a function definition
      • 52、error C2450: switch expression of type 'xxx' is illegal
      • 53、error C2466: cannot allocate an array of constant size 0
      • 54、error C2601: 'xxx' : local function definitions are illegal
      • 55、error C2632: 'type1' followed by 'type2' is illegal
      • 56、error C2660: 'xxx' : function does not take n parameters
      • 57、error C2664: 'xxx' : cannot convert parameter n from 'type1' to 'type2'
      • 58、error C2676: binary '<<' : 'class istream_withassign' does not define this operator or a conversion to a type acceptable to the predefined operator error C2676: binary '>>' : 'class ostream_withassign' does not define this operator or a conversion to a type acceptable to the predefined operator
      • 59、error C4716: 'xxx' : must return a value
      • 60、fatal error LNK1104: cannot open file "Debug/Cpp1.exe"
      • 61、fatal error LNK1168: cannot open Debug/Cpp1.exe for writing
      • 62、fatal error LNK1169: one or more multiply defined symbols found
      • 63、error LNK2001: unresolved external symbol _main
      • 64、error LNK2005: _main already defined in Cpp1.obj
      • 65、warning C4003: not enough actual parameters for macro 'xxx'
      • 66、warning C4067: unexpected tokens following preprocessor directive - expected a newline
      • 67、warning C4091: '' : ignored on left of 'type' when no variable is declared
      • 68、warning C4101: 'xxx' : unreferenced local variable
      • 69、warning C4244: '=' : conversion from 'type1' to 'type2', possible loss of data
      • 70、warning C4305: 'initializing' : truncation from 'const double' to 'float'
      • 71、warning C4390: ';' : empty controlled statement found; is this the intent?
      • 72、warning C4508: 'xxx' : function should return a value; 'void' return type assumed
      • 73、warning C4552: 'operator' : operator has no effect; expected operator with side-effect
      • 74、warning C4553: '==' : operator has no effect; did you intend '='?
      • 75、warning C4700: local variable 'xxx' used without having been initialized
      • 76、warning C4715: 'xxx' : not all control paths return a value
      • 77、warning C4723: potential divide by 0
      • 78、warning C4804: '<' : unsafe use of type 'bool' in operation

转载自编程论坛-“自学的数学"的帖子

1、fatal error C1003: error count exceeds number; stopping compilation

中文对照:(编译错误)错误太多,停止编译
分析:修改之前的错误,再次编译

2、fatal error C1004: unexpected end of file found

中文对照:(编译错误)文件未结束
分析:一个函数或者一个结构定义缺少“}”、或者在一个函数调用或表达式中括号没有配对出现、或者注释符“//”不完整等

3、fatal error C1083: Cannot open include file: ‘xxx’: No such file or directory

中文对照:(编译错误)无法打开头文件xxx:没有这个文件或路径
分析:头文件不存在、或者头文件拼写错误、或者文件为只读

4、fatal error C1903: unable to recover from previous error(s); stopping compilation

中文对照:(编译错误)无法从之前的错误中恢复,停止编译
分析:引起错误的原因很多,建议先修改之前的错误

5、error C2001: newline in constant

中文对照:(编译错误)常量中创建新行
分析:字符串常量多行书写

6、error C2006: #include expected a filename, found ‘identifier’

中文对照:(编译错误)#include命令中需要文件名
分析:一般是头文件未用一对双引号或尖括号括起来,例如“#include stdio.h”

7、error C2007: #define syntax

中文对照:(编译错误)#define语法错误
分析:例如“#define”后缺少宏名,例如“#define”

8、error C2008: ‘xxx’ : unexpected in macro definition

中文对照:(编译错误)宏定义时出现了意外的xxx
分析:宏定义时宏名与替换串之间应有空格,例如“#define TRUE"1"”

9、error C2009: reuse of macro formal ‘identifier’

中文对照:(编译错误)带参宏的形式参数重复使用
分析:宏定义如有参数不能重名,例如“#define s(a,a) (a*a)”中参数a重复

10、error C2010: ‘character’ : unexpected in macro formal parameter list

中文对照:(编译错误)带参宏的形式参数表中出现未知字符
分析:例如“#define s(r|) r*r”中参数多了一个字符‘|’

11、error C2014: preprocessor command must start as first nonwhite space

中文对照:(编译错误)预处理命令前面只允许空格
分析:每一条预处理命令都应独占一行,不应出现其他非空格字符

12、error C2015: too many characters in constant

中文对照:(编译错误)常量中包含多个字符
分析:字符型常量的单引号中只能有一个字符,或是以“\”开始的一个转义字符,例如“char error = ‘error’;”

13、error C2017: illegal escape sequence

中文对照:(编译错误)转义字符非法
分析:一般是转义字符位于 ’ ’ 或 " " 之外,例如“char error = ’ '\n;”

14、error C2018: unknown character ‘0xhh’

中文对照:(编译错误)未知的字符0xhh
分析:一般是输入了中文标点符号,例如“char error = ‘E’;”中“;”为中文标点符号

15、error C2019: expected preprocessor directive, found ‘character’

中文对照:(编译错误)期待预处理命令,但有无效字符
分析:一般是预处理命令的#号后误输入其他无效字符,例如“#!define TRUE 1”

16、error C2021: expected exponent value, not ‘character’

中文对照:(编译错误)期待指数值,不能是字符
分析:一般是浮点数的指数表示形式有误,例如123.456E

17、error C2039: ‘identifier1’ : is not a member of ‘identifier2’

中文对照:(编译错误)标识符1不是标识符2的成员
分析:程序错误地调用或引用结构体、共用体、类的成员

18、error C2041: illegal digit ‘x’ for base ‘n’

中文对照:(编译错误)对于n进制来说数字x非法
分析:一般是八进制或十六进制数表示错误,例如“int i = 081;”语句中数字‘8’不是八进制的基数

19、error C2048: more than one default

中文对照:(编译错误)default语句多于一个
分析:switch语句中只能有一个default,删去多余的default

20、error C2050: switch expression not integral

中文对照:(编译错误)switch表达式不是整型的
分析:switch表达式必须是整型(或字符型),例如“switch (“a”)”中表达式为字符串,这是非法的

21、error C2051: case expression not constant

中文对照:(编译错误)case表达式不是常量
分析:case表达式应为常量表达式,例如“case “a””中““a””为字符串,这是非法的

22、error C2052: ‘type’ : illegal type for case expression

中文对照:(编译错误)case表达式类型非法
分析:case表达式必须是一个整型常量(包括字符型)

23、error C2057: expected constant expression

中文对照:(编译错误)期待常量表达式
分析:一般是定义数组时数组长度为变量,例如“int n=10; int a[n];”中n为变量,这是非法的

24、error C2058: constant expression is not integral

中文对照:(编译错误)常量表达式不是整数
分析:一般是定义数组时数组长度不是整型常量

25、error C2059: syntax error : ‘xxx’

中文对照:(编译错误)‘xxx’语法错误
分析:引起错误的原因很多,可能多加或少加了符号xxx

26、error C2064: term does not evaluate to a function

中文对照:(编译错误)无法识别函数语言
分析:1、函数参数有误,表达式可能不正确,例如“sqrt(s(s-a)(s-b)(s-c));”中表达式不正确 2、变量与函数重名或该标识符不是函数,例如“int i,j; j=i();”中i不是函数

27、error C2065: ‘xxx’ : undeclared identifier

中文对照:(编译错误)未定义的标识符xxx
分析:1、如果xxx为cout、cin、scanf、printf、sqrt等,则程序中包含头文件有误 2、未定义变量、数组、函数原型等,注意拼写错误或区分大小写。

28、error C2078: too many initializers

中文对照:(编译错误)初始值过多
分析:一般是数组初始化时初始值的个数大于数组长度,例如“int b[2]={1,2,3};”

29、error C2082: redefinition of formal parameter ‘xxx’

中文对照:(编译错误)重复定义形式参数xxx
分析:函数首部中的形式参数不能在函数体中再次被定义

30、error C2084: function ‘xxx’ already has a body

中文对照:(编译错误)已定义函数xxx
分析:在VC++早期版本中函数不能重名,6.0版本中支持函数的重载,函数名可以相同但参数不一样

31、error C2086: ‘xxx’ : redefinition

中文对照:(编译错误)标识符xxx重定义
分析:变量名、数组名重名

32、error C2087: ‘’ : missing subscript

中文对照:(编译错误)下标未知
分析:一般是定义二维数组时未指定第二维的长度,例如“int a[3][];”

33、error C2100: illegal indirection

中文对照:(编译错误)非法的间接访问运算符“
分析:对非指针变量使用“
”运算

34、error C2105: ‘operator’ needs l-value

中文对照:(编译错误)操作符需要左值
分析:例如“(a+b)++;”语句,“++”运算符无效

35、error C2106: ‘operator’: left operand must be l-value

中文对照:(编译错误)操作符的左操作数必须是左值 分析:
例如“a+b=1;”语句,“=”运算符左值必须为变量,不能是表达式

36、error C2110: cannot add two pointers

中文对照:(编译错误)两个指针量不能相加
分析:例如“int *pa,*pb,*a; a = pa + pb;”中两个指针变量不能进行“+”运算

37、error C2117: ‘xxx’ : array bounds overflow

中文对照:(编译错误)数组xxx边界溢出
分析:一般是字符数组初始化时字符串长度大于字符数组长度,例如“char str[4] = “abcd”;”

38、error C2118: negative subscript or subscript is too large

中文对照:(编译错误)下标为负或下标太大
分析:一般是定义数组或引用数组元素时下标不正确 error C2124: divide or mod by zero 中文对照:(编译错误)被零除或对0求余 分析:例如“int i = 1 / 0;”除数为0

39、error C2133: ‘xxx’ : unknown size

中文对照:(编译错误)数组xxx长度未知
分析:一般是定义数组时未初始化也未指定数组长度,例如“int a[];”

40、error C2137: empty character constant。

中文对照:(编译错误)字符型常量为空
分析:一对单引号“’’”中不能没有任何字符

41、error C2143: syntax error : missing ‘token1’ before ‘token2’

42、error C2146: syntax 4error : missing ‘token1’ before identifier ‘identifier’

中文对照:(编译错误)在标识符或语言符号2前漏写语言符号1
分析:可能缺少“{”、“)”或“;”等语言符号

43、error C2144: syntax error : missing ‘)’ before type ‘xxx’

中文对照:(编译错误)在xxx类型前缺少‘)’
分析:一般是函数调用时定义了实参的类型

44、error C2181: illegal else without matching if

中文对照:(编译错误)非法的没有与if相匹配的else
分析:可能多加了“;”或复合语句没有使用“{}”

45、error C2196: case value ‘0’ already used

中文对照:(编译错误)case值0已使用
分析:case后常量表达式的值不能重复出现

46、error C2296: ‘%’ : illegal, left operand has type ‘float’

47 error C2297: ‘%’ : illegal, right operand has type ‘float’

中文对照:(编译错误)%运算的左(右)操作数类型为float,这是非法的
分析:求余运算的对象必须均为int类型,应正确定义变量类型或使用强制类型转换

48、error C2371: ‘xxx’ : redefinition; different basic types

中文对照:(编译错误)标识符xxx重定义;基类型不同
分析:定义变量、数组等时重名

49、error C2440: ‘=’ : cannot convert from ‘char [2]’ to ‘char’

中文对照:(编译错误)赋值运算,无法从字符数组转换为字符
分析:不能用字符串或字符数组对字符型数据赋值,更一般的情况,类型无法转换

50、error C2447: missing function header (old-style formal list?)

51、error C2448: ‘’ : function-style initializer appears to be a function definition

中文对照:(编译错误)缺少函数标题(是否是老式的形式表?)
分析:函数定义不正确,函数首部的“( )”后多了分号或者采用了老式的C语言的形参表

52、error C2450: switch expression of type ‘xxx’ is illegal

中文对照:(编译错误)switch表达式为非法的xxx类型
分析:switch表达式类型应为int或char

53、error C2466: cannot allocate an array of constant size 0

中文对照:(编译错误)不能分配长度为0的数组
分析:一般是定义数组时数组长度为0

54、error C2601: ‘xxx’ : local function definitions are illegal

中文对照:(编译错误)函数xxx定义非法
分析:一般是在一个函数的函数体中定义另一个函数

55、error C2632: ‘type1’ followed by ‘type2’ is illegal

中文对照:(编译错误)类型1后紧接着类型2,这是非法的
分析:例如“int float i;”语句

56、error C2660: ‘xxx’ : function does not take n parameters

中文对照:(编译错误)函数xxx不能带n个参数
分析:调用函数时实参个数不对,例如“sin(x,y);”

57、error C2664: ‘xxx’ : cannot convert parameter n from ‘type1’ to ‘type2’

中文对照:(编译错误)函数xxx不能将第n个参数从类型1转换为类型2
分析:一般是函数调用时实参与形参类型不一致

58、error C2676: binary ‘<<’ : ‘class istream_withassign’ does not define this operator or a conversion to a type acceptable to the predefined operator error C2676: binary ‘>>’ : ‘class ostream_withassign’ does not define this operator or a conversion to a type acceptable to the predefined operator

分析:“>>”、“<<”运算符使用错误,例如“cin<>y;”

59、error C4716: ‘xxx’ : must return a value

中文对照:(编译错误)函数xxx必须返回一个值
分析:仅当函数类型为void时,才能使用没有返回值的返回命令。

60、fatal error LNK1104: cannot open file “Debug/Cpp1.exe”

中文对照:(链接错误)无法打开文件Debug/Cpp1.exe
分析:重新编译链接

61、fatal error LNK1168: cannot open Debug/Cpp1.exe for writing

中文对照:(链接错误)不能打开Debug/Cpp1.exe文件,以改写内容。
分析:一般是Cpp1.exe还在运行,未关闭

62、fatal error LNK1169: one or more multiply defined symbols found

中文对照:(链接错误)出现一个或更多的多重定义符号。
分析:一般与error LNK2005一同出现

63、error LNK2001: unresolved external symbol _main

中文对照:(链接错误)未处理的外部标识main
分析:一般是main拼写错误,例如“void mian()”

64、error LNK2005: _main already defined in Cpp1.obj

中文对照:(链接错误)main函数已经在Cpp1.obj文件中定义
分析:未关闭上一程序的工作空间,导致出现多个main函数

65、warning C4003: not enough actual parameters for macro ‘xxx’

中文对照:(编译警告)宏xxx没有足够的实参
分析:一般是带参宏展开时未传入参数

66、warning C4067: unexpected tokens following preprocessor directive - expected a newline

中文对照:(编译警告)预处理命令后出现意外的符号 - 期待新行
分析:“#include;”命令后的“;”为多余的字符

67、warning C4091: ‘’ : ignored on left of ‘type’ when no variable is declared

中文对照:(编译警告)当没有声明变量时忽略类型说明
分析:语句“int ;”未定义任何变量,不影响程序执行

68、warning C4101: ‘xxx’ : unreferenced local variable

中文对照:(编译警告)变量xxx定义了但未使用
分析:可去掉该变量的定义,不影响程序执行

69、warning C4244: ‘=’ : conversion from ‘type1’ to ‘type2’, possible loss of data

中文对照:(编译警告)赋值运算,从数据类型1转换为数据类型2,可能丢失数据
分析:需正确定义变量类型,数据类型1为float或double、数据类型2为int时,结果有可能不正确,数据类型1为double、数据类型2为float时,不影响程序结果,可忽略该警告

70、warning C4305: ‘initializing’ : truncation from ‘const double’ to ‘float’

中文对照:(编译警告)初始化,截取双精度常量为float类型
分析:出现在对float类型变量赋值时,一般不影响最终结果

71、warning C4390: ‘;’ : empty controlled statement found; is this the intent?

中文对照:(编译警告)‘;’控制语句为空语句,是程序的意图吗?
分析:if语句的分支或循环控制语句的循环体为空语句,一般是多加了“;”

72、warning C4508: ‘xxx’ : function should return a value; ‘void’ return type assumed

中文对照:(编译警告)函数xxx应有返回值,假定返回类型为void
分析:一般是未定义main函数的类型为void,不影响程序执行 c语言的错误对照表———— 在遇到错误时可以对照查看

73、warning C4552: ‘operator’ : operator has no effect; expected operator with side-effect

中文对照:(编译警告)运算符无效果;期待副作用的操作符
分析:例如“i+j;”语句,“+”运算无意义

74、warning C4553: ‘==’ : operator has no effect; did you intend ‘=’?

中文对照:(编译警告)“”运算符无效;是否为“=”?
分析:例如 “i
j;” 语句,“==”运算无意义

75、warning C4700: local variable ‘xxx’ used without having been initialized

中文对照:(编译警告)变量xxx在使用前未初始化
分析:变量未赋值,结果有可能不正确,如果变量通过scanf函数赋值,则有可能漏写“&”运算符,或变量通过cin赋值,语句有误

76、warning C4715: ‘xxx’ : not all control paths return a value

中文对照:(编译警告)函数xxx不是所有的控制路径都有返回值
分析:一般是在函数的if语句中包含return语句,当if语句的条件不成立时没有返回值

77、warning C4723: potential divide by 0

中文对照:(编译警告)有可能被0除
分析:表达式值为0时不能作为除数

78、warning C4804: ‘<’ : unsafe use of type ‘bool’ in operation

中文对照:(编译警告)‘<’:不安全的布尔类型的使用
分析:例如关系表达式“0<=x<10”有可能引起逻辑错误

参考:

C语言常见编译错误及分析

C语言常见编译错误分类及其解决方案

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

C语言常见编译错误及分析 的相关文章

  • Errors were encountered while processing: google-chrome-stable

    转自 xff1a http omtlab com errors were encountered while processing google chrome stable Many people facing this issue whi
  • virtualbox 命令

    VBoxManage命令详解 xff08 一 xff09 本人对vboxmange命令按我个人的理解作了解释 xff0c 由于本人水平有限难免有错误的地方 xff0c 希望大家帮我指正 VBoxManage v version 显示virt
  • 基于Springboot的物业管理系统_代码

    下载地址 1 1 课题背景 目的及意义 1 1 1 课题背景 互联网 43 改变着我们的生活 xff0c 在传统的社区物业服务领域 xff0c 在服务业主 提升社区服务 质量方面 xff0c 如何与互联网融合 xff1f 顶级互联网技术团队
  • eclips运行generatorConfig.xml文件生成代码

    描述 xff1a 如何通过eclips工具来运行 generatorConfig xml 文件来自动生成代码并获取数据 xff08 类似于mybaits逆向生成 xff09 xff1f mybatis generator generate
  • Spring源码(4)Context篇之AbstractApplicationContext(下)

    上一篇 Spring源码 4 Context篇之AbstractApplicationContext xff08 上 xff09 讲解了Spring的AbstractApplicationContext类refresh 方法 xff0c 前
  • java多线程 一个生产者和多个消费者

    生产者和消费者模式是面试时很容易被问到的一类题 xff0c 在平常的开发中也经常碰到 xff0c 比如在网游开发中 xff1a 用一个线程把收到的字节数据封装起来写到一个队列中 xff0c 然后用一个或多个线程从该队列中把数据读取出来再分发
  • Python最强装逼神技!微信远程控制电脑,想让你电脑关机就关机!

    今天带给大家一个非常有意思的 python 程序 xff0c 基于 itchat 实现微信控制电脑 你可以通过在微信发送命令 xff0c 来拍摄当前电脑的使用者 xff0c 然后图片会发送到你的微信上 甚至你可以发送命令来远程关闭电脑 程序
  • JAVA 在linux下面生成验证码异常问题

    应用部署到Linux下 xff0c 结果首页登录的验证码显示不出来 该验证码是用java的图片包来处理图片的 xff0c 后台日志报错 xff1a java lang NoClassDefFoundError sun awt X11Grap
  • 【PowerShell 一天一练】 3. 调用winrar解压

    如果你安装了 winrar 且安装在对应下面的路径 xff0c 可以尝试一下下面的代码 xff08 事实上我也是 copy 并修改自网上的代码 xff09 unrar 61 c Program files winrar unrar exe
  • C/C++中二维数组和指针关系分析

    在C c 43 43 中 xff0c 数组和指针有着密切的关系 xff0c 有很多地方说数组就是指针式错误的一种说法 这两者是不同的数据结构 其实 xff0c 在C c 43 43 中没有所谓的二维数组 xff0c 书面表达就是数组的数组
  • 四叉树空间索引原理及其实现

    今天依然在放假中 xff0c 在此将以前在学校写的四叉树的东西拿出来和大家分享 四叉树索引的基本思想是将地理空间递归划分为不同层次的树结构 它将已知范围的空间等分成四个相等的子空间 xff0c 如此递归下去 xff0c 直至树的层次达到一定
  • DirectXShaderCompiler mac编译

    Directxshader compiler mac编译 1 前置条件 Please make sure you have the following resources before building GitPython Version
  • intel -tbb 源码cmake构建

    cmake minimum required VERSION 3 0 0 FATAL ERROR set CMAKE CXX STANDARD 17 project tbb CXX add library tbb SHARED void c
  • iOS编译openmp

    1 下载openmp源码 https github com llvm llvm project releases download llvmorg 14 0 6 openmp 14 0 6 src tar xz 2 下载ios toolch
  • mysql存储过程及拼接字符串的用法

    DROP PROCEDURE IF EXISTS insert historytable DELIMITER CREATE PROCEDURE insert historytable BEGIN 定义判断变量 DECLARE 1 id va
  • 矩阵的特征值和特征向量的雅克比算法C/C++实现

    矩阵的特征值和特征向量是线性代数以及矩阵论中非常重要的一个概念 在遥感领域也是经常用到 xff0c 比如多光谱以及高光谱图像的主成分分析要求解波段间协方差矩阵或者相关系数矩阵的特征值和特征向量 根据普通线性代数中的概念 xff0c 特征值和
  • windows多线程详解

    在一个牛人的博客上看到了这篇文章 xff0c 所以就转过来了 xff0c 地址是http blog csdn net morewindows article details 7421759 本文将带领你与多线程作第一次亲密接触 xff0c
  • tiff文件读取

    以下是VC下读取TIFF文件的代码 char szFileName 61 34 K 地图 fujian DEM fujian1 tif 34 TIFF tiff 61 TIFFOpen szFileName 34 r 34 打开Tiff文件
  • GIS开发人员需要掌握的知识和技能

    对于GIS行业 xff0c 可能很多人不是很了解 xff0c 对我来说也不是很了解 xff0c 在此呢 xff0c 我就我自己的看法发表一下简单的看法 xff0c 有什么不同的意见可以一起交流 GIS虽说是属于地理科学或者说测绘科学与技术的

随机推荐