c语言常见错误提示
- 格式:pdf
- 大小:159.89 KB
- 文档页数:7
1.调试 C 程序时常见的错误类型分析一般情况下,错误主要分为两大类:一、语法错误。
对于这种错误,用编译器很容易解决。
所以,改错题的第一步是先编译,解决这类语法错误。
下面总结了二级C 语言上机改错题中常见的语法错误:(1) 丢失分号,或分号误写成逗号。
(2) 关键字拼写错误,如本来小写变成大写。
(3) 语句格式错误,例如for 语句中多写或者少写分号。
(4) 表达式声明错误,例如:少了()(5) 函数类型说明错误。
与main ()函数中不一致。
(6) 函数形参类型声明错误。
例如:少* 等。
(7) 运算符书写错误,例如:/ 写成了。
二、逻辑错误,或者叫语义错误,这和实现程序功能紧密相关,一般不能用编译器发现。
对于逻辑错误可以按这样的步骤进行查找。
(1) 先读试题,看清题目的功能要求。
(2) 通读程序,看懂程序中算法的实现方法。
(3) 细看程序,发现常见错误点。
2.改错题的改错方式总结,当然这些总结只能对大部分改错行有效1、若错误行是函数首部,可分为以下几种情况:A、该行最后若有分号则删除,中间若有分号则改成逗号B、形参类型不一致的问题,特别是指针类型,若后面用到某形参时有指针运算则该形参必为指针类型;若形参是二维数组或指向m 个元素的指针变量,则第二维的长度必须与main 中对应数组的第二维长度相同C、函数类型不一致的问题,若函数中没有return语句则函数类型为void,若有return语句则函数的类型必须与return 后变量的类型一致。
2、若错误行是if 或while 语句,则首先看有没有用小括号将整个表达式括起,若没有则加上小括号。
3、若错误行中有if、while 、for 则要特别注意条件表达式的错误问题:A、指针变量的应用,若表达式中有指针变量且没有指针运算符,则加上指针运算符B、若条件表达式中只有一个等于号,则改成两个等于号,若为其它比较运算符则一般是进行逆转或加一个等于号C、f or 中要用分号分隔表达式,而不是用逗号4、语法错误A、语句缺少分号,若错误行中有语句没有用分号结束,则加上分号。
gcc 常见的编译警告与错误(按字母顺序排列)C语言初学者遇到的最大问题往往是看不懂编译错误,进而不知如何修改程序。
有鉴于此,本附录罗列了用gcc编译程序时经常出现的编译警告与错误。
需要提醒读者的是,出现警告(warning)并不影响目标程序的生成,但出现错误(error)则无法生成目标程序。
为便于读者查阅,下面列出了经常遇到的警告与错误,给出了中英文对照(英文按字典顺序排列),并对部分错误与警告做了必要的解释。
#%s expects \FILENAME\ or …#%s 需要 \FILENAME\ 或…#%s is a deprecated GCC extension#%s 是一个已过时的 GCC 扩展#%s is a GCC extension#%s 是一个 GCC 扩展#~ error:#~ 错误:#~ In file included from %s:%u#~ 在包含自 %s:%u 的文件中#~ internal error:#~ 内部错误:#~ no newline at end of file#~ 文件未以空白行结束#~ warning:#~ 警告:#elif after #else#elif 出现在 #else 后#elif without #if#elif 没有匹配的 #if#else after #else#else 出现在 #else 后#else without #if#else 没有匹配的 #if#endif without #if#endif 没有匹配的 #if#include nested too deeply#include 嵌套过深#include_next in primary source file#include_next 出现在主源文件中#pragma %s %s is already registered#pragma %s %s 已经被注册#pragma %s is already registered#pragma %s 已经被注册#pragma once in main file#pragma once 出现在主文件中#pragma system_header ignored outside include file#pragma system_heade 在包含文件外被忽略%.*s is not a valid universal character%.*s 不是一个有效的 Unicode 字符%s in preprocessing directive预处理指示中出现 %s%s is a block device%s 是一个块设备%s is shorter than expected%s 短于预期%s is too large%s 过大%s with no expression%s 后没有表达式%s: not used because `%.*s’ defined as `%s’ not `%.*s’ %s:未使用因为‘%.*s’被定义为‘%s’而非‘%*.s’%s: not used because `%.*s’ is poisoned%s:未使用因为‘%.*s’已被投毒%s: not used because `%.*s’ not def ined%s:未使用因为‘%.*s’未定义%s: not used because `%s’ is defined%s:未使用因为‘%s’已定义%s: not used because `__COUNTER__’ is invalid%s:未使用因为‘__COUNTER__’无效(\%s\ is an alternative token for \%s\ in C++)(在 C++ 中“%s”会是“%s”的替代标识符)(this will be reported only once per input file)(此警告为每个输入文件只报告一次)\%s\ after # is not a positive integer# 后的“%s”不是一个正整数\%s\ after #line is not a positive integer#line 后的“%s”不是一个正整数\%s\ cannot be used as a macro name as it is an operator in C++ “%s”不能被用作宏名,因为它是 C++ 中的一个操作符\%s\ is not a valid filename“%s”不是一个有效的文件名\%s\ is not defined“%s”未定义\%s\ may not appear in macro parameter list“%s不能出现在宏参数列表中\%s\ re-asserted重断言“%s”\%s\ redefined“%s重定义\/*\ within comment“/*出现在注释中\\x used with no following hex digits\\x 后没有 16 进制数字\defined\ cannot be used as a macro name“defined不能被用作宏名__COUNTER__ expanded inside directive with -fdirectives-only带 -fdirectives-only 时 __COUNTER__ 在指示中扩展__VA_ARGS__ can only appear in the expansion of a C99 variadic macro __VA_ARGS__ 只能出现在 C99 可变参数宏的展开中_Pragma takes a parenthesized string literal_Pragma 需要一个括起的字符串字面常量‘%.*s’ is not in NFC‘%.*s’不在 NFC 中‘%.*s’ is not in NFKC‘%.*s’不在 NFKC 中‘##’ cannot appear at either end of a macro expansion‘##’不能出现在宏展开的两端‘#’ is not followed by a macro parameter‘#’后没有宏参数‘$’ in identifier or number‘$’出现在标识符或数字中‘:’ without preceding ‘?’‘:’前没有‘?’‘?’ without following ‘:’‘?’后没有‘:’'return' with a value, in function returning void在void返回类型的函数中,return返回值。
Ambiguous operators need parentheses 不明确的运算需要用括号括起Ambiguous symbol ''xxx''不明确的符号Argument list syntax error参数表语法错误Array bounds missing丢失数组界限符Array size toolarge数组尺寸太大Bad character in paramenters参数中有不适当的字符Bad file name format in include directive 包含命令中文件名格式不正确Bad ifdef directive synatax编译预处理ifdef有语法错Bad undef directive syntax编译预处理undef有语法错Bit field too large位字段太长Call of non-function调用未定义的函数Call to function with no prototype调用函数时没有函数的说明Cannot modify a const object不允许修改常量对象Case outside of switch漏掉了case 语句Case syntax errorCase 语法错误Code has no effect代码不可述不可能执行到Compound statement missing{分程序漏掉"{"Conflicting type modifiers不明确的类型说明符Constant expression required要求常量表达式Constant out of range in comparison在比较中常量超出范围Conversion may lose significant digits转换时会丢失意义的数字Conversion of near pointer not allowed 不允许转换近指针Could not find file ''xxx''找不到XXX文件Declaration missing ;说明缺少";"Declaration syntax error说明中出现语法错误Default outside of switchDefault 出现在switch语句之外Define directive needs an identifier定义编译预处理需要标识符Division by zero用零作除数Do statement must have whileDo-while语句中缺少while部分Enum syntax error枚举类型语法错误Enumeration constant syntax error枚举常数语法错误Error directive :xxx错误的编译预处理命令Error writing output file写输出文件错误Expression syntax error表达式语法错误Extra parameter in call调用时出现多余错误File name too long文件名太长Function call missing )函数调用缺少右括号Fuction definition out of place函数定义位置错误Fuction should return a value函数必需返回一个值Goto statement missing labelGoto语句没有标号Hexadecimal or octal constant too large 16进制或8进制常数太大Illegal character ''x''非法字符xIllegal initialization非法的初始化Illegal octal digit非法的8进制数字Illegal pointer subtraction非法的指针相减Illegal structure operation非法的结构体操作Illegal use of floating point非法的浮点运算Illegal use of pointer指针使用非法Improper use of a typedefsymbol类型定义符号使用不恰当In-line assembly not allowed不允许使用行间汇编Incompatible storage class存储类别不相容Incompatible type conversion不相容的类型转换Incorrect number format错误的数据格式Incorrect use of defaultDefault使用不当Invalid indirection无效的间接运算Invalid pointer addition指针相加无效Irreducible expression tree无法执行的表达式运算Lvalue required需要逻辑值0或非0值Macro argument syntax error宏参数语法错误Macro expansion too long宏的扩展以后太长Mismatched number of parameters in definition 定义中参数个数不匹配Misplaced break此处不应出现break语句Misplaced continue此处不应出现continue语句Misplaced decimal point此处不应出现小数点Misplaced elif directive不应编译预处理elifMisplaced else此处不应出现elseMisplaced else directive此处不应出现编译预处理else Misplaced endif directive此处不应出现编译预处理endif Must be addressable必须是可以编址的Must take address of memory location 必须存储定位的地址No declaration for function ''xxx''没有函数xxx的说明No stack缺少堆栈No type information没有类型信息Non-portable pointer assignment不可移动的指针(地址常数)赋值Non-portable pointer comparison不可移动的指针(地址常数)比较Non-portable pointer conversion不可移动的指针(地址常数)转换Not a valid expression format type不合法的表达式格式Not an allowed type不允许使用的类型Numeric constant too large数值常太大Out of memory内存不够用Parameter ''xxx'' is never used能数xxx没有用到Pointer required on left side of ->符号->的左边必须是指针Possible use of ''xxx'' before definition 在定义之前就使用了xxx(警告)Possibly incorrect assignment赋值可能不正确Redeclaration of ''xxx''重复定义了xxxRedefinition of ''xxx'' is not identical xxx的两次定义不一致Register allocation failure寄存器定址失败Repeat count needs an lvalue重复计数需要逻辑值Size of structure or array not known结构体或数给大小不确定Statement missing ;语句后缺少";"Structure or union syntax error结构体或联合体语法错误Structure size too large结构体尺寸太大Sub scripting missing ]下标缺少右方括号Superfluous & with function or array函数或数组中有多余的"&" Suspicious pointer conversion可疑的指针转换Symbol limit exceeded符号超限Too few parameters in call函数调用时的实参少于函数的参数不Too many default casesDefault太多(switch语句中一个)Too many error or warning messages错误或警告信息太多Too many type in declaration说明中类型太多Too much auto memory in function函数用到的局部存储太多Too much global data defined in file文件中全局数据太多Two consecutive dots两个连续的句点Type mismatch in parameter xxx参数xxx类型不匹配Type mismatch in redeclaration of ''xxx'' xxx重定义的类型不匹配Unable to create output file ''xxx''无法建立输出文件xxxUnable to open include file ''xxx''无法打开被包含的文件xxxUnable to open input file ''xxx''无法打开输入文件xxxUndefined label ''xxx''没有定义的标号xxxUndefined structure ''xxx''没有定义的结构xxxUndefined symbol ''xxx''没有定义的符号xxxUnexpected end of file in comment started on line xxx 从xxx行开始的注解尚未结束文件不能结束Unexpected end of file in conditional started on line xxx 从xxx 开始的条件语句尚未结束文件不能结束Unknown assemble instruction未知的汇编结构Unknown option未知的操作Unknown preprocessor directive: ''xxx''不认识的预处理命令xxxUnreachable code无路可达的代码Unterminated string or character constant字符串缺少引号User break用户强行中断了程序Void functions may not return a valueVoid类型的函数不应有返回值Wrong number of arguments调用函数的参数数目错''xxx'' not an argumentxxx不是参数''xxx'' not part of structurexxx不是结构体的一部分xxx statement missing (xxx语句缺少左括号xxx statement missing )xxx语句缺少右括号xxx statement missing ;xxx缺少分号xxx'' declared but never used说明了xxx但没有使用xxx'' is assigned a value which is never used给xxx赋了值但未用过Zero length structure结构体的长度为零。
C语言错误提示Ambiguous operators need parentheses -------不明确的运算需要用括号括起Ambiguous symbol ''xxx'' ---------------- 不明确的符号Argument list syntax error ---------------- 参数表语法错误Array bounds missing ------------------ 扔掉数组界限符Array size toolarge ----------------- 数组尺寸太大 Bad character in paramenters ------ ------------ 参数中有不合适的字符Bad file name format in include directive ------------ 包含命令中文件名格式不正确Bad ifdef directive synatax ------------------ 编译预办理 ifdef 有语法错Bad undef directive syntax ------------------- 编译预办理 undef 有语法错Bit field too large ---------------- 位字段太长Call of non-function ----------------- 调用不决义的函数Call to function with no prototype ----------- 调用函数时没有函数的说明Cannot modify a const object ---------------不一样意修改常量对象Case outside of switch ----------------遗漏了 case语句Case syntax error ------------------ Case 语法错误 Code has no effect ----------------- 代码不能述不能能执行到Compound statement missing{ -------------------- 分程序遗漏 "{"Conflicting type modifiers ------------------ 不明确的种类说明符Constant expression required ----------------要求常量表达式Constant out of range in comparison --------------在比较中常量超出范围Conversion may lose significant digits ---------变换时会扔掉意义的数字Conversion of near pointer not allowed ---------------不一样意变换近指针Could not find file ''xxx'' -----------------------找不到XXX文件Declaration missing ; ---------------- 说明缺少 " ; " Declaration syntax error ----------- ------ 说明中出现语法错误Default outside of switch -------------- Default 出现在 switch 语句之外Define directive needs an identifier ---------定义编译预办理需要表记符Division by zero ------------------ 用零作除数Do statement must have while ----------- Do-while 语句中缺少 while 部分Enum syntax error --------------------- 列举种类语法错误Enumeration constant syntax error -----------------列举常数语法错误Error directive :xxx ------------------------ 错误的编译预办理命令Error writing output file ---------------------写输出文件错误Expression syntax error ----------------------- 表达式语法错误Extra parameter in call ------------------------ 调用时出现节余错误File name too long ---------------- 文件名太长Function call missing ----------------- 函数调用缺少右括号Fuction definition out of place ------------------ 函数定义地址错误Fuction should return a value ------------------函数必需返回一个值Goto statement missing label ------------------ Goto 语句没有标号Hexadecimal or octal constant too large -------16进制或 8 进制常数太大Illegal character ''x'' ------------------ 非法字符 x Illegal initialization ------------------ 非法的初始化Illegal octal digit ------------------ 非法的 8 进制数字Illegal pointer subtraction ------------------ 非法的指针相减Illegal structure operation ------------------ 非法的结构体操作Illegal use of floating point ----------------- 非法的浮点运算Illegal use of pointer -------------------- 指针使用非法Improper use of a typedefsymbol ----------------种类定义符号使用不合适In-line assembly not allowed ----------------- 不一样意使用行间汇编Incompatible storage class -----------------储藏种类不相容Incompatible type conversion -------------------- 不相容的种类变换Incorrect number format ----------------------- 错误的数据格式Incorrect use of default --------------------- Default 使用不当Invalid indirection --------------------- 无效的间接运算Invalid pointer addition ------------------ 指针相加无效Irreducible expression tree --------------------- 无法执行的表达式运算Lvalue required --------------------------- 需要逻辑值 0 或非 0 值Macro argument syntax error ------------------- 宏参数语法错误Macro expansion too long ---------------------- 宏的扩展今后太长Mismatched number of parameters in definition ----定义中参数个数不般配Misplaced break --------------------- 此处不应出现 break 语句Misplaced continue ------------------------ 此处不应出现 continue 语句Misplaced decimal point -------------------- 此处不应出现小数点Misplaced elif directive -------------------- 不应编译预办理 elifMisplaced else ---------------------- 此处不应出现 elseMisplaced else directive ------------------ 此处不应出现编译预办理elseMisplaced endif directive ----------------- 此处不应出现编译预办理endifMust be addressable ----------------------必定是能够编址的Must take address of memory location ---------------必定储藏定位的地址No declaration for function ''xxx'' ---------------- 没有函数 xxx 的说明No stack --------------- 缺少货仓No type information ------------------ 没有种类信息Non-portable pointer assignment -------- 不能搬动的指针(地址常数赋值Non-portable pointer comparison --------不能搬动的指针 (地址常数比较Non-portable pointer conversion --------不能搬动的指针(地址常数变换Not a valid expression format type ----------------- 不合法的表达式格式Not an allowed type --------------------- 不一样意使用的种类Numeric constant too large ------------------- 数值常太大Out of memory ------------------- 内存不够用 Parameter ''xxx'' is never used ----------- ------- 能数 xxx 没适用到Pointer required on left side of -> ------------符号->的左边必定是指针Possible use of ''xxx'' before definition ----------在定义从前就使用了xxx ( 警告Possibly incorrect assignment ----------------赋值可能不正确Redeclaration of ''xxx'' ------------------- 重复定义了 xxxRedefinition of ''xxx'' is not identical -------- xxx 的两次定义不一致Register allocation failure ------------------ 寄存器定址失败Repeat count needs an lvalue ------------------重复计数需要逻辑值Size of structure or array not known -----------结构体或数给大小不确定Statement missing ; ------------------语句后缺少 " ; " Structure or union syntax error -------------- 结构体或联合体语法错误Structure size too large ----------------结构体尺寸太大Sub scripting missing ] ---------------- 下标缺少右方括号Superfluous & with function or array ----------- 函数或数组中有节余的"&"Suspicious pointer conversion --------------------- 可疑的指针变换Symbol limit exceeded --------------- 符号超限Too few parameters in call -----------函数调用时的实参少于函数的参数不Too many default cases ----------------- Default 太多 (switch 语句中一个Too many error or warning messages -----------------错误或警告信息太多Too many type in declaration ----------------- 说明中种类太多Too much auto memory in function --------------- 函数用到的局部储藏太多Too much global data defined in file --------------- 文件中全局数据太多Two consecutive dots ----------------- 两个连续的句点Type mismatch in parameter xxx ---------------- 参数 xxx 种类不般配Type mismatch in redeclaration of ''xxx'' ----- xxx 重定义的种类不般配Unable to create output file ''xxx'' -------------- 无法建立输出文件xxxUnable to open include file ''xxx'' ----------- 无法打开被包含的文件xxxUnable to open input file ''xxx'' ---------------- 无法打开输入文件xxxUndefined label ''xxx'' ------------------- 没有定义的标号 xxxUndefined structure ''xxx'' ----------------- 没有定义的结构 xxxUndefined symbol ''xxx'' ----------------- 没有定义的符号 xxxUnexpected end of file in comment started on line xxx:从 xxx 行开始的解说还没有结束文件不能够结束Unexpected end of file in conditional started on line xxx :从 xxx 开始的条件语句还没有结束文件不能够结束Unknown assemble instruction ----------------未知的汇编结构Unknown option --------------- 未知的操作Unknown preprocessor directive: ''xxx'' ---------不认识的预办理命令xxxUnreachable code ------------------无路可达的代码Unterminated string or character constant------------- 字符串缺少引号User break ---------------- 用户强行中断了程序Void functions may not return a value ---- Void 种类的函数不应有返回值Wrong number of arguments -----------------调用函数的参数数目错''xxx'' not an argument ----------------- xxx 不是参数''xxx'' not part of structure ----------------- xxx 不是结构体的一部分xxx statement missing ( -------------------- xxx 语句缺少左括号xxx statement missing ------------------ xxx 语句缺少右括号xxx statement missing ; -------------------- xxx 缺少分号xxx'' declared but never used -------------------说了然 xxx 但没有使用xxx'' is assigned a value which is never used ----给 xxx 赋了值但未用过Zero length structure ------------------ 结构体的长度为零警告类错误1‘ XXX’ declare but never used变量 XXX 已定义但从未用过。
conflicting types for ‘read’“conflictingtypesfor‘read’”这个错误是C语言中常见的编译错误。
当编写代码时,我们常常会在函数的参数或返回值类型上出现不一致的情况,导致编译器不能正确识别函数的定义。
本文将探讨这种错误的原因,以及如何避免它。
错误的原因在C语言中,函数的定义必须与其声明一致。
如果一个函数在不同的位置有不同的声明,那么编译器会认为这个函数有多个定义,从而报出“conflicting types for”错误。
例如,下面的代码就会导致这个错误:```#include <stdio.h>int read(int x) {printf('The value of x is %d', x);return 0;}int main() {int n = 5;read(n);return 0;}```编译器会提示“conflicting types for ‘read’”,因为在程序中,我们定义了一个名为read的函数,但是在stdio.h头文件中也有一个名为read的函数,且两个函数的参数类型不同。
如何避免这个错误?避免“conflicting types for”错误的方法很简单:确保所有函数的定义和声明一致。
具体来说,有以下几点需要注意:1.头文件的使用在程序中使用头文件时,应该仔细查看头文件中包含的函数和变量,以避免与程序中的函数和变量重名。
如果必须使用同名函数或变量,应该使用不同的命名空间或别名来区分它们。
2.函数声明的一致性在不同的源文件中使用同一个函数时,应该在所有源文件中使用相同的函数声明。
建议将函数声明放在头文件中,以便在需要时引用。
3.参数类型和返回类型的一致性在函数定义和声明时,应该确保参数类型和返回类型一致。
如果参数类型或返回类型不同,编译器会视其为不同的函数,从而导致“conflicting types for”错误。
二级C语言编程常见的18种错误C语言的最大特点是:功能强、使用方便灵活。
C编译的程序对语法检查并不象其它高级语言那么严格,这就给编程人员留下“灵活的余地”,但还是由于这个灵活给程序的调试带来了许多不便,尤其对初学C语言的人来说,经常会出一些连自己都不知道错在哪里的错误。
看着有错的程序,不知该如何改起,校园网整理了一些C编程时常犯的错误,写给各位学员以供参考。
1.书写标识符时,忽略了大小写字母的区别main(){int a=5;printf("%d",A);}编译程序把a和A认为是两个不同的变量名,而显示出错信息。
C认为大写字母和小写字母是两个不同的字符。
习惯上,符号常量名用大写,变量名用小写表示,以增加可读性。
2.忽略了变量的类型,进行了不合法的运算。
main(){float a,b;printf("%d",a%b);}%是求余运算,得到a/b的整余数。
整型变量a和b可以进行求余运算,而实型变量则不允许进行“求余”运算。
3.将字符常量与字符串常量混淆。
char c;c="a";在这里就混淆了字符常量与字符串常量,字符常量是由一对单引号括起来的单个字符,字符串常量是一对双引号括起来的字符序列。
C规定以“\”作字符串结束标志,它是由系统自动加上的,所以字符串“a”实际上包含两个字符:…a'和…\',而把它赋给一个字符变量是不行的。
4.忽略了“=”与“= =”的区别。
在许多高级语言中,用“=”符号作为关系运算符“等于”。
如在BASIC程序中可以写if (a=3) then …但C语言中,“=”是赋值运算符,“==”是关系运算符。
如:if (a==3) a=b;前者是进行比较,a是否和3相等,后者表示如果a和3相等,把b值赋给a。
由于习惯问题,初学者往往会犯这样的错误。
5.忘记加分号。
分号是C语句中不可缺少的一部分,语句末尾必须有分号。
C语⾔编程中常见的五种错误及对应解决⽅案⽬录1. 未初始化的变量2. 数组越界3. 字符串溢出4. 重复释放内存5. 使⽤⽆效的⽂件指针前⾔:C 语⾔有时名声不太好,因为它不像近期的编程语⾔(⽐如 Rust)那样具有内存安全性。
但是通过额外的代码,⼀些最常见和严重的 C 语⾔错误是可以避免的。
即使是最好的程序员也⽆法完全避免错误。
这些错误可能会引⼊安全漏洞、导致程序崩溃或产⽣意外操作,具体影响要取决于程序的运⾏逻辑。
下⽂讲解了可能影响应⽤程序的五个错误以及避免它们的⽅法:1. 未初始化的变量程序启动时,系统会为其分配⼀块内存以供存储数据。
这意味着程序启动时,变量将获得内存中的⼀个随机值。
有些编程环境会在程序启动时特意将内存“清零”,因此每个变量都得以有初始的零值。
程序中的变量都以零值作为初始值,听上去是很不错的。
但是在 C 编程规范中,系统并不会初始化变量。
看⼀下这个使⽤了若⼲变量和两个数组的⽰例程序:#include <stdio.h>#include <stdlib.h>intmain(){int i, j, k;int numbers[5];int *array;puts("These variables are not initialized:");printf(" i = %d\n", i);printf(" j = %d\n", j);printf(" k = %d\n", k);puts("This array is not initialized:");for (i = 0; i < 5; i++) {printf(" numbers[%d] = %d\n", i, numbers[i]);}puts("malloc an array ...");array = malloc(sizeof(int) * 5);if (array) {puts("This malloc'ed array is not initialized:");for (i = 0; i < 5; i++) {printf(" array[%d] = %d\n", i, array[i]);}free(array);}/* done */puts("Ok");return 0;}这个程序不会初始化变量,所以变量以系统内存中的随机值作为初始值。
C语言常见错误提示(英汉对照)TurboC2.0编译错误信息详解TurboC编译程序检查源程序中三类出错信息:致命错误、一般错误、警告。致命错误:通常是内部编译错误。发生致命错误时,编译立即停止,必须采取一些适当的措施并重新编译。一般错误:指程序的语法错误、磁盘或内存存取错误或命令错误。警告:它并不阻止编译进行。它指出一些值得怀疑的情况,而这些情况本身又有可能合理地成为源程序的一部分。注意:编译程序指产生被检测到的信息,因为C并不限定在正文的某行放一条语句,这样,真正产生错误的行可能在编译指出的前一行或几行。Ambiguousoperatorsneedparentheses不明确的运算需要用括号括起Ambiguoussymbol“xxx”不明确的符号Argumentlistsyntaxerror参数表语法错误Arrayboundsmissing丢失数组界限符Arraysizetoolarge数组尺寸太大Badcharacterinparamenters参数中有不适当的字符Badfilenameformatinincludedirective包含命令中文件名格式不正确Badifdefdirectivesynatax编译预处理ifdef有语法错Badundefdirectivesyntax编译预处理undef有语法错Bitfieldtoolarge位字段太长Callofnon-function调用未定义的函数Calltofunctionwithnoprototype调用函数时没有函数的说明Cannotmodifyaconstobject不允许修改常量对象Caseoutsideofswitch漏掉了case语句CasesyntaxerrorCase语法错误Codehasnoeffect代码不可述不可能执行到Compoundstatementmissing{分程序漏掉"{"Conflictingtypemodifiers不明确的类型说明符Constantexpressionrequired要求常量表达式Constantoutofrangeincomparison在比较中常量超出范围Conversionmaylosesignificantdigits转换时会丢失意义的数字Conversionofnearpointernotallowed不允许转换近指针Couldnotfindfile“xxx”找不到XXX文件Declarationmissing;说明缺少";"Declarationsyntaxerror说明中出现语法错误DefaultoutsideofswitchDefault出现在switch语句之外Definedirectiveneedsanidentifier定义编译预处理需要标识符Divisionbyzero用零作除数DostatementmusthavewhileDo-while语句中缺少while部分Enumsyntaxerror枚举类型语法错误Enumerationconstantsyntaxerror枚举常数语法错误Errordirective:xxx错误的编译预处理命令Errorwritingoutputfile写输出文件错误Expressionsyntaxerror表达式语法错误Extraparameterincall调用时出现多余错误Filenametoolong文件名太长Functioncallmissing)函数调用缺少右括号Fuctiondefinitionoutofplace函数定义位置错误Fuctionshouldreturnavalue函数必需返回一个值GotostatementmissinglabelGoto语句没有标号Hexadecimaloroctalconstanttoolarge16进制或8进制常数太大Illegalcharacter“x”非法字符xIllegalinitialization非法的初始化Illegaloctaldigit非法的8进制数字Illegalpointersubtraction非法的指针相减Illegalstructureoperation非法的结构体操作Illegaluseoffloatingpoint非法的浮点运算Illegaluseofpointer指针使用非法Improperuseofatypedefsymbol类型定义符号使用不恰当In-lineassemblynotallowed不允许使用行间汇编Incompatiblestorageclass存储类别不相容Incompatibletypeconversion不相容的类型转换Incorrectnumberformat错误的数据格式IncorrectuseofdefaultDefault使用不当Invalidindirection无效的间接运算Invalidpointeraddition指针相加无效Irreducibleexpressiontree无法执行的表达式运算Lvaluerequired需要逻辑值0或非0值Macroargumentsyntaxerror宏参数语法错误Macroexpansiontoolong宏的扩展以后太长Mismatchednumberofparametersindefinition定义中参数个数不匹配Misplacedbreak此处不应出现break语句Misplacedcontinue此处不应出现continue语句Misplaceddecimalpoint此处不应出现小数点Misplacedelifdirective不应编译预处理elifMisplacedelse此处不应出现elseMisplacedelsedirective此处不应出现编译预处理elseMisplacedendifdirective此处不应出现编译预处理endifMustbeaddressable必须是可以编址的Musttakeaddressofmemorylocation必须存储定位的地址Nodeclarationforfunction“xxx”没有函数xxx的说明Nostack缺少堆栈Notypeinformation没有类型信息Non-portablepointerassignment不可移动的指针(地址常数)赋值Non-portablepointercomparison不可移动的指针(地址常数)比较Non-portablepointerconversion不可移动的指针(地址常数)转换Notavalidexpressionformattype不合法的表达式格式Notanallowedtype不允许使用的类型Numericconstanttoolarge数值常太大Outofmemory内存不够Parameter“xxx”isneverused能数xxx没有用到Pointerrequiredonleftsideof->符号->的左边必须是指针Possibleuseof“xxx”beforedefinition在定义之前就使用了xxx(警告)Possiblyincorrectassignment赋值可能不正确Redeclarationof“xxx”重复定义了xxxRedefinitionof“xxx”isnotidenticalxxx的两次定义不一致Registerallocationfailure寄存器定址失败Repeatcountneedsanlvalue重复计数需要逻辑值Sizeofstructureorarraynotknown结构体或数给大小不确定Statementmissing;语句后缺少";"Structureorunionsyntaxerror结构体或联合体语法错误Structuresizetoolarge结构体尺寸太大Subscriptingmissing]下标缺少右方括号Superfluous&withfunctionorarray函数或数组中有多余的"&"Suspiciouspointerconversion可疑的指针转换Symbollimitexceeded符号超限Toofewparametersincall函数调用时的实参少于函数的参数不ToomanydefaultcasesDefault太多(switch语句中一个)Toomanyerrororwarningmessages错误或警告信息太多Toomanytypeindeclaration说明中类型太多Toomuchautomemoryinfunction函数用到的局部存储太多Toomuchglobaldatadefinedinfile文件中全局数据太多Twoconsecutivedots两个连续的句点Typemismatchinparameterxxx参数xxx类型不匹配Typemismatchinredeclarationof“xxx”xxx重定义的类型不匹配Unabletocreateoutputfile“xxx”无法建立输出文件xxxUnabletoopenincludefile“xxx”无法打开被包含的文件xxxUnabletoopeninputfile“XXX”无法打开输入文件xxxUndefinedlabel“XXX”没有定义的标号xxxUndefinedstructure“XXX”没有定义的结构xxxUndefinedsymbol“XXX”没有定义的符号xxxUnexpectedendoffileincommentstartedonlinexxx