预处理器 - 它可以做出有条件的决定 [英] Preprocessor - can it make conditional decisions

查看:71
本文介绍了预处理器 - 它可以做出有条件的决定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!


预处理器可以做出有条件的决定。这是一个

功能的例子(不是标准的C!)


#define PUT_BYTE(const_index,val)\

#preprocessor_if(const_index == 0)\

({*(77)=(val);})\

#preratoror_else_if(const_index == 1)\

({*(99)=(val);})\

#prederor_end


可以上面的剪辑是在C ??


-anon.asdf

解决方案

在文章< 11 ********************* @ m37g2000prh.googlegroups中。 com>,

< an ******* @ gmail.comwrote:


>预处理器能做出有条件的决定吗? 。这是一个功能的例子(不是标准的C!)

#define PUT_BYTE(const_index,val)\

#preratoror_if(const_index = = 0)\

({*(77)=(val);})\

#preratoror_else_if(const_index == 1)\

({*(99)=(val);})\

#prederor_end



No.但在此特殊情况,如果您只使用普通的if,

,编译器将能够看到条件是恒定的并且

可能会生成相同的代码如果你能够在预处理器中做到这一点

。另一方面,对于条件不变的条件,它可能会发出警告




- Richard

-

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

- 1963年的X3.4。


8月10日下午2:47,Chris Dollin< chris.dol ... @ hp.comwrote:


什么时候`({*(99)=(val);})`成为合法语法?这是我错过的一些C99

,还是我很幸运能逃脱的专有主义?



我的错误!

({*((int *)99)=(val);})

就是这个意思。

谢谢!


一个******* @ gmail.com 写道:


8月10日下午2:47, Chris Dollin< chris.dol ... @ hp.comwrote:


>什么时候`({*(99)=(val);})`成为合法语法?这是我错过的一些C99
,还是我很幸运能逃脱的专有主义?



我的错误!

({*((int *)99)=(val);})

就是这个意思。

谢谢!



(a)什么时候`({*((int *)99)=(val);})`成为合法语法(fx:etc)?


(b)据推测,你知道将一个整数转换为一个指针然后

通过它分配是非常不可移植的,并且极其可能

在钢丝绳上跳舞时玩杂耍剑的好理由

被蒙上眼睛,而目前失业的鼻腔恶魔呼吸

结霜的温柔火焰。

-

克里斯不要恐慌! Dollin


Hewlett-Packard Limited注册号:

注册办事处:Cain Road,Bracknell,Berks RG12 1HN 690597英格兰


Hello!

Can the proprocessor make conditional decisions. Here''s an example of
the functionality (not standard C!)

#define PUT_BYTE(const_index, val) \
#preprocessor_if (const_index == 0) \
({ *(77) = (val); }) \
#preprocessor_else_if (const_index == 1) \
({ *(99) = (val); }) \
#preprocessor_end

Could the above snipped be done in C??

-anon.asdf

解决方案

In article <11*********************@m37g2000prh.googlegroups. com>,
<an*******@gmail.comwrote:

>Can the proprocessor make conditional decisions. Here''s an example of
the functionality (not standard C!)

#define PUT_BYTE(const_index, val) \
#preprocessor_if (const_index == 0) \
({ *(77) = (val); }) \
#preprocessor_else_if (const_index == 1) \
({ *(99) = (val); }) \
#preprocessor_end

No. But in this particular case, if you just use an ordinary "if",
the compiler will be able to see that the condition is constant and
will probably generate the same code as if you had been able to do it
in the preprocessor. On the other hand, it may well give a warning
for a conditional with a constant condition.

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


On Aug 10, 2:47 pm, Chris Dollin <chris.dol...@hp.comwrote:

When did `({ *(99) = (val); })` become legal syntax? Is this some C99
thing I missed, or a proprietaryism I''ve been lucky to escape?

My mistake!
({ *((int *)99) = (val); })
is what was meant.
Thanks!


an*******@gmail.com wrote:

On Aug 10, 2:47 pm, Chris Dollin <chris.dol...@hp.comwrote:

>When did `({ *(99) = (val); })` become legal syntax? Is this some C99
thing I missed, or a proprietaryism I''ve been lucky to escape?


My mistake!
({ *((int *)99) = (val); })
is what was meant.
Thanks!

(a) When did `({ *((int *)99) = (val); })` become legal syntax (fx:etc)?

(b) Presumably you know that casting an integer to a pointer and then
assigning through it is horribly unportable, and have Extremely
Good Reasons for juggling swords while dancing on a tightrope
blindfolded while a currently-unemployed nasal demon breaths
gentle flames over the knots.

--
Chris "DON''T PANIC!" Dollin

Hewlett-Packard Limited registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England


这篇关于预处理器 - 它可以做出有条件的决定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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