如果存在两个#defines,如何强制编译错误? [英] How do I force a compiler error if two #defines exist?

查看:65
本文介绍了如果存在两个#defines,如何强制编译错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可以用#defines编译的项目。


说: -

#define firstdef

#define seconddef


如果没有定义或只有一个定义,则一切正常。如果两个

#defines都存在,我会在代码中添加一个自检来防止编译。这可能吗?

解决方案

9月24日,9月27日,Eliot< e ... @ hotmail.comwrote:


我有一个项目可以用一些#defines编译。


说: -

#define firstdef

#define seconddef


如果没有定义或只有一个定义,则一切正常。如果两个

#defines都存在,我会在代码中添加一个自检来防止编译。这可能吗?



#if defined(firstdef)&&已定义(seconddef)

#error"无法定义firstdef和seconddef"

#endif


< blockquote>文章< 11 ********************* @ n39g2000hsh.googlegroups。 com>,

Eliot< eb*@hotmail.comwrote:


> #define firstdef
#define seconddef

如果没有定义或只有一个定义,则一切正常。如果两个
#define都存在,我会想要在代码中添加自检以阻止编译。这可能吗?



#if defined(firstdef)&&定义(seconddef)

#error不能定义两个

#endif


- Richard

-

在一些字母表中需要考虑多达32个字符

- X3.4,1963。


Eliot< eb*@hotmail.comwrote:


>我有一个项目可以用一些#defines编译。

说: -
#define firstdef
#define seconddef

如果没有定义是现在或只有一个存在都可以。如果两个
#define都存在,我会想要在代码中添加自检以阻止编译。这可能吗?



#if defined(fistdef)&&定义(secondef)

#error不要这样做!

#endif

Roberto Waltman


[请回复小组,

返回地址无效]


I have a project which may be compiled with some #defines.

Say:-
#define firstdef
#define seconddef

If no defines are present or only one is present all is OK. I would
like to add a self check to the code that prevents compilation if both
#defines are present. Is this possible?

解决方案

On 9 24 , 9 27 , Eliot <e...@hotmail.comwrote:

I have a project which may be compiled with some #defines.

Say:-
#define firstdef
#define seconddef

If no defines are present or only one is present all is OK. I would
like to add a self check to the code that prevents compilation if both
#defines are present. Is this possible?

#if defined(firstdef) && defined(seconddef)
#error "Cannot define both firstdef and seconddef"
#endif


In article <11*********************@n39g2000hsh.googlegroups. com>,
Eliot <eb*@hotmail.comwrote:

>#define firstdef
#define seconddef

If no defines are present or only one is present all is OK. I would
like to add a self check to the code that prevents compilation if both
#defines are present. Is this possible?

#if defined(firstdef) && defined(seconddef)
#error Mustn''t define both
#endif

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.


Eliot <eb*@hotmail.comwrote:

>I have a project which may be compiled with some #defines.

Say:-
#define firstdef
#define seconddef

If no defines are present or only one is present all is OK. I would
like to add a self check to the code that prevents compilation if both
#defines are present. Is this possible?

#if defined(fistdef) && defined(secondef)
#error Don''t do this!
#endif
Roberto Waltman

[ Please reply to the group,
return address is invalid ]


这篇关于如果存在两个#defines,如何强制编译错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆