C语言教程:#error指令

2018-10-1307:49:36编程语言入门到精通Comments2,633 views字数 486阅读模式

#error预处理程序指令用于指示错误。如果找到#error指令编译器将发出致命错误,并且跳过进一步的编译过程。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/6619.html

#error示例文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/6619.html

我们来看一个简单的例子来使用#error预处理器指令。创建一个源文件:error-example.c,其代码如下所示 -文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/6619.html

#include <stdio.h>

#ifndef PI  
#error First include then compile  
#else  
void main() {
    float a = 1000.999;
    printf("b = %f\n", a);
}
#endif
C

执行上面示例代码,得到以下结果 -文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/6619.html

Compile Time Error: First include then compile
C

创建一个源文件:error-example2.c,其代码如下所示 -文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/6619.html

#include <stdio.h>
#define PI  3.14159

#ifndef PI  
#error First include then compile  
#else  
void main() {
    float a = 1000.999;
    printf("b = %f\n", a);
}
#endif
C

执行上面示例代码,得到以下结果 -文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/6619.html

b = 1000.999023
文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/6619.html
  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/ymba/6619.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定