#error的用法

  • #error用于生成一个编译错误消息

    • 用法:error message(不需要用双引号包围)
  • #error编译指示字用于自定义程序员特有的编译错误,消息类似的
  • #warning用于生成编译警告
  • #error是一种预编译器指示字
  • #error可用于提示编译条件是否满足

编译过程中的任意错误信息意味着无法生成最终的可执行程序

例子1:#error预处理初探

#include<stdio.h>

#ifndef __cplusplus
#error This file should be processed with c++ compliler.
#endif // __cplusplus class CppClass
{
private:
int m_value;
public:
CppClass(){}
~CppClass(){}
}; int main()
{
return 0;
}

#line的用法

#line用于强制制定新的行号和编译文件名,并对源程序的代码重新编号

用法:#line number filename(filename可以省略)

#line编译指示字的本质是重定义 LINE__和__FILE

#include <stdio.h>    

int main()
{
printf("%s : %d\n", __FILE__, __LINE__); #line 1 "change.c" printf("%s : %d\n", __FILE__, __LINE__); return 0;
}

小结

  • #error用于自定义一条编译错误信息
  • #warning用于自定义一条编译警告信息
  • #error和#warning常用于条件编译的情形
  • #line用于强制指定新的行号和编译文件名

#error和#line使用分析的更多相关文章

  1. 第23课 - #error 和 #line 使用分析

    第23课 - #error 和 #line 使用分析 1. #error 的用法 (1)#error 是一个预处理器指示字,用于生成一个编译错误消息,这个消息最终会传递到编译器(gcc) 在思考这一点 ...

  2. 第23课 #error和#line使用分析

    #error的用法: 示例程序: #include <stdio.h> #ifndef __cplusplus #error This file should be processed w ...

  3. Error on line -1 of document : Premature end of file. Nested exception: Premature end of file.

    启动tomcat, 出现, ( 之前都是好好的... ) [lk ] ERROR [08-12 15:10:02] [main] org.springframework.web.context.Con ...

  4. 关于xml加载提示: Error on line 1 of document : 前言中不允许有内容

    我是在java中做的相关测试, 首先粘贴下报错: 读取xml配置文件:xmls\property.xml org.dom4j.DocumentException: Error on line 1 of ...

  5. (转载)Flash Loader加载完成不发送COMPLETE和ERROR事件的问题分析

    (转载)http://blog.dou.li/flash-loader%E5%8A%A0%E8%BD%BD%E5%AE%8C%E6%88%90%E4%B8%8D%E5%8F%91%E9%80%81co ...

  6. error on line 1 at column 6: XML declaration allowed only at the start of the document

    This page contains the following errors: error on line 1 at column 6: XML declaration allowed only a ...

  7. "fatal: protocol error: bad line length character: No This"

    git clone 远程地址时候出现 "fatal: protocol error: bad line length character: No This" 错误 在stackov ...

  8. Parse Fatal Error at line 41 column 24: 元素类型 "url-pattern" 必须由匹配的结束标记 "</url-pattern>" 终止

    1.错误描述 严重: Parse Fatal Error at line 41 column 24: 元素类型 "url-pattern" 必须由匹配的结束标记 "< ...

  9. (转)Windows 平台下解决httpd.exe: syntax error on line 39

    近来在研究PHP,结果为了Apache的安装伤神不已...小白我在安装后,启动Apache的服务虽然可以,不过,在Apache sevice monitor 中启动services时就会出现如下的问题 ...

随机推荐

  1. HDU1300 Pearls —— 斜率优化DP

    题目链接:https://vjudge.net/problem/HDU-1300 Pearls Time Limit: 2000/1000 MS (Java/Others)    Memory Lim ...

  2. get all sites under IIS

    https://stackoverflow.com/questions/2555668/how-to-programmatically-get-sites-list-and-virtual-dirs- ...

  3. 网站页面打开浏览器table中显示图片

    就类似博客园这种:

  4. js 购物车中,多件商品数量加减效果修改,实现总价随数量加减改变

    <!DOCTYPE html> <html> <head> <meta charset=UTF-8 /> <title>无标题文档</ ...

  5. liunx命令之【查看某个端口号的使用情况】

    第一:查看端口占用情况的命令:lsof -i:<端口号>

  6. Lua变量

    Lua 变量 变量在使用前,必须在代码中进行声明,即创建该变量. 编译程序执行代码之前编译器需要知道如何给语句变量开辟存储区,用于存储变量的值. Lua 变量有三种类型:全局变量.局部变量.表中的域. ...

  7. linux以行为单位进行读写操作

    1 gets/fgets函数 char* fgets(char *restrict buf,int n,FILE *restrict fp) 参数1:存放读入串的缓冲区 参数2:表示读入的字符个数,最 ...

  8. 任务34:Cookie-based认证实现

    任务34:Cookie-based认证实现 用mvc来实现以下Cookie-Base的认证和授权的方式 新建一个web MVC的项目 在我的电脑的路径:D:\MyDemos\jesse Ctrl+鼠标 ...

  9. git 基本命令详细解释

    创建: 2017-04-05 17:04:03         2017-04-24 更新: 2017-05-16 更新: 2017-06-27  完善git remote add  更新: 2017 ...

  10. 洛谷 - P1034 - 矩形覆盖 - dfs

    https://www.luogu.org/problemnew/show/P1034 可能是数据太水了瞎搞都可以过. 判断两个平行于坐标轴的矩形相交(含顶点与边相交)的代码一并附上. 记得这里的xy ...