宏来控制基于日期的条件编译 [英] macro to control conditional compilation based on date

查看:65
本文介绍了宏来控制基于日期的条件编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都遇到过一个预处理器宏,它将

参数值与预定义的__DATE__宏进行比较,以便

根据日期控制条件编译。 />

有些东西......


#define DateLaterThan(x)...


可以用于


#if DateLaterThan(" Jun 15 2006")

#error现在可以删除以下调试代码

#end

能够在源代码中留下强有力的提醒非常方便

代码以提示清除丑陋的快速修复,临时诊断等等
等而不是被动的TODO / FIXME类型注释标签。

-

comp.lang.c.moderated - 审核地址: cl**@plethora.net - 您必须

在您的标题中有适当的新闻组行要看的邮件,

或方形br中的新闻组名称主题行中的ackets。对不起。

Anyone out there ever come across a preprocessor macro that compares an
argument value against the predefined __DATE__ macro in order to
control conditional compilation based on date.

Something along the lines of...

# define DateLaterThan(x) ...

that could be used for things like

#if DateLaterThan("Jun 15 2006")
#error The following debug code can be deleted now
#end
Would be pretty handy to be able to leave a forceful reminder in souce
code to prompt cleanup of ugly quick fixes, tempory diagnostics etc.
etc. rather than passive TODO/FIXME type comment tags.
--
comp.lang.c.moderated - moderation address: cl**@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.

推荐答案



< ri ********* @ my-deja.com>在消息中写道

news:cl **************** @ plethora.net ...

<ri*********@my-deja.com> wrote in message
news:cl****************@plethora.net...
有人来过跨预处理器宏,将
参数值与预定义的__DATE__宏进行比较,以便根据日期控制条件编译。
Anyone out there ever come across a preprocessor macro that compares an
argument value against the predefined __DATE__ macro in order to
control conditional compilation based on date.




(第一个帖子是昨天也是comp.lang.c.moderated,所以它'

可能会在一周后出现在这里......;)


Nope。


但是,你可能可能能够使用assert(),strcmp(),

localtime(),strftime()和__DATE__做类似的事情。

Rod Pemberton



(First post was yesterday and also to comp.lang.c.moderated , so it''ll
probably show up here a week from now... ;)

Nope.

But, you "might" be able to do something similar using assert(), strcmp(),
localtime(), strftime(), and __DATE__.
Rod Pemberton


2006年3月10日星期五05:09, ri ****** ***@my-deja.com 认为(

< cl **************** @ plethora.net>):
On Friday 10 March 2006 05:09, ri*********@my-deja.com opined (in
<cl****************@plethora.net>):
任何人都会遇到一个预处理器宏,它将参数值与预定义的__DATE__宏进行比较,以便根据日期控制条件编译。 br />
有些东西......

#define DateLaterThan(x)......

可用于

#if DateLaterThan(" Jun 15 2006")
#error现在可以删除以下调试代码
#end

将是非常方便的能够在源代码中留下强有力的提醒,以提示清除丑陋的快速修复,临时诊断等。
et c。而不是被动的TODO / FIXME类型的注释标签。
Anyone out there ever come across a preprocessor macro that compares
an argument value against the predefined __DATE__ macro in order to
control conditional compilation based on date.

Something along the lines of...

# define DateLaterThan(x) ...

that could be used for things like

#if DateLaterThan("Jun 15 2006")
#error The following debug code can be deleted now
#end
Would be pretty handy to be able to leave a forceful reminder in souce
code to prompt cleanup of ugly quick fixes, tempory diagnostics etc.
etc. rather than passive TODO/FIXME type comment tags.




__DATE__不是标准C的一部分,`DateLaterThan`当然不是$ />
。我希望有些编译器可以实现前者,但

如果后者属于这种情况,我会感到惊讶。


全部这是偏离主题的(仅讨论标准C)。你在你的特定编译器组中提出的问题要好得多。但请注意,如果你在某个时候更改编译器,那么你很整洁

解决方案可能会停止工作。


-

BR,Vladimir


Warp 7 - 这是我们可以接受的法律。

-

comp.lang.c.moderated - 审核地址: cl**@plethora.net - - 您必须

在您的标题中有一个适当的新闻组行,以便查看您的邮件,

或主题行中方括号中的新闻组名称。对不起。



__DATE__ is not part of standard C, and `DateLaterThan` certainly isn''t
either. I''d expect that some compilers may implement the former, but
I''d be surprised if that were the case for the latter.

All this is off-topic here (only standard C is discussed). You''re much
better of asking in your particular compiler''s group. Note, however,
that if you change compilers sometime down the line, you''re neat
solution is likely to stop working.

--
BR, Vladimir

Warp 7 -- It''s a law we can live with.
--
comp.lang.c.moderated - moderation address: cl**@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.


ri ******* **@my-deja.com 写道:
任何人都遇到过一个预处理器宏,它将
参数值与预定义的__DATE__宏进行比较,以便
控制基于日期的条件编译。

有些事情......

#definition DateLaterThan(x)......

可以用于

#if DateLaterThan(" Jun 15 2006")
#error现在可以删除以下调试代码
#end

能够在源代码中留下强有力的提醒,以提示清除丑陋的快速修复,临时诊断等等,而不是被动的TODO / FIXME类型注释标签,这将非常方便。
Anyone out there ever come across a preprocessor macro that compares an
argument value against the predefined __DATE__ macro in order to
control conditional compilation based on date.

Something along the lines of...

# define DateLaterThan(x) ...

that could be used for things like

#if DateLaterThan("Jun 15 2006")
#error The following debug code can be deleted now
#end
Would be pretty handy to be able to leave a forceful reminder in souce
code to prompt cleanup of ugly quick fixes, tempory diagnostics etc.
etc. rather than passive TODO/FIXME type comment tags.




__DATE__在标准C中不可用。即使您的编译器提供了

它,您也可以按照您想要的方式使用它, 它的不会是

便携式。切换到不同的编译器几乎肯定会打破它的b $ b。如果你仍然想要追求这个大道,最好在讨论你的特定编译器的

小组中询问。


一个想法:为什么要'你是否要求TODO / FIXME以#b>
的方式进行#ifdef-ed类似于:


#if FIXME

#error"这需要立即修复!"

#else

/ *你的临时修复* /

#endif


然后,在正常的日子里你#define(或作为编译器的选项传递)

FIXME为0,特殊场合为1.如果你通过它

编译器命令行,你也可以玩传递时间相关的

值并与之进行比较。不过,这仍然可能是不便携的。


-

BR,Vladimir

-

comp.lang.c.moderated - 审核地址: cl ** @ plethora.net - 您必须

在您的标题中有适当的新闻组行,以便查看您的邮件,

或主题行中方括号中的新闻组名称。对不起。



__DATE__ is not available in standard C. Even if your compiler provides
it, and you can use it in the way you want, it''s not going to be
portable. Switching to a different compiler is almost certain to break
it. If you still want to pursue this avenue, it''s best asking in the
group that discusses your particular compiler.

An idea: why don''t you mandate that TODO/FIXMEs are #ifdef-ed in a
manner similar to:

#if FIXME
#error "This needs fixing NOW!"
#else
/* your temporary fix */
#endif

Then, on normal days you #define (or pass as an option to the compiler)
FIXME as 0, and on special occassions as 1. If you pass it through the
compiler command line, you may also play with passing time-dependant
value and comparing against it. This is still likely to be
non-portable, though.

--
BR, Vladimir
--
comp.lang.c.moderated - moderation address: cl**@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.


这篇关于宏来控制基于日期的条件编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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