#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. hdu-2066 一个人的旅行(最短路spfa)

    题目链接: 一个人的旅行 Time Limit: 1000/1000 MS (Java/Others)     Memory Limit: 32768/32768 K (Java/Others) Pr ...

  2. Android studio Unable to run mksdcard SDK tool

    /******************************************************************************************** * Andr ...

  3. 【AHOI2009】中国象棋

    [题目链接] 点击打开链接 [算法] 动态规划 f[i][j][k]表示前i行,有j列放了1个,有k列放了两个 分六种情况讨论即可 [代码] #include<bits/stdc++.h> ...

  4. 【POJ 1061】 青蛙的约会

    [题目链接] 点击打开链接 [算法] 列出同余方程,然后用exgcd求解 [代码] #include <algorithm> #include <bitset> #includ ...

  5. bzoj3143游走——期望+高斯消元

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3143 只需算出每条边被经过的概率,将概率从小到大排序,从大到小编号,就可得到最小期望: 每条 ...

  6. [转载]文件过滤驱动 文件系统激活通知 IoRegisterFsRegistrationChange函数实现

    IoRegisterFsRegistrationChange 注册一个文件系统变动回调函数,用来被通知文件系统的激活和注销,激活是指第一次加载文件系统,当一个文件系统已经加载后,当加载一个同种文件系统 ...

  7. 如何用JavaScript实现获取验证码的效果

    转自:http://www.php.cn/js-tutorial-411734.html HTML部分: 1 2 3 4 5 6 7 <body onload='createCode()'> ...

  8. MySQL中的RAND()函数使用详解

    转自:https://www.jb51.net/article/66697.htm MySQL RAND()函数调用可以在0和1之间产生一个随机数: ? 1 2 3 4 5 6 7 mysql> ...

  9. 1. jsp中<base target='' />标签用法

    用于页面跳转后,页面最后跳转到哪个iframe.例子如下: index.jsp :首页 <head> <base href="<%=basePath %>&qu ...

  10. E20180502-hm

    inject vt. (给…)注射(药物等) ; (给…)注射(液体) ; (给…) 添加; (给…)投入(资金) ; reduce  vt. 减少; 缩小; 使还原; 使变弱;       vi. ...