预处理器的可能性 [英] Preprocessor possibilities

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

问题描述

是否可以编写一个宏(在未扩展的C89中),以便


TEST(int,(1,2,3));


扩展为


int array [] = {1,2,3};


?我强烈怀疑它不是,但我不想忽视一个

解决方案(如果存在的话)。


-

Christopher Benson-Manica |我*应该*知道我在说什么 - 如果我

ataru(at)cyberspace.org |不,我需要知道。火焰欢迎。

解决方案




Christopher Benson-Manica写于12/13/05 12:39 ,:

是否可以编写一个宏(在未扩展的C89中),以便

TEST(int,(1,2,3));

扩展到

int array [] = {1,2,3};

?我强烈怀疑它不是,但我不想忽视一个
解决方案,如果存在。




#define TEST(类型,列表)type array [] = {list}


这看起来很简单 - 我不知怎的

误读了你的问题?


-
Er ********* @ sun.com




Eric Sosman写道:

Christopher Benson-Manica写道12/13 / 05 12:39,:

是否可以编写一个宏(在未扩展的C89中),以便

TEST(int,(1,2,3));

扩展到

int array [] = {1,2,3};

?我强烈怀疑它不是,但我不想忽视一个
解决方案,如果存在。



#define TEST(type,list)类型数组[ ] = {list}

这看起来非常简单 - 我不知何故
误读了你的问题?

-
Er ********* @ sun.com




括号怎么样?我想他正试图避免C99 varargs

宏。


-David


blockquote>
< blockquote> David Resnick< ln ******** @ gmail.com>写道:

括号怎么样?我想他正试图避免使用C99 varargs
宏。




是的,我是。我正在处理一个不支持C99 varargs宏的C ++实现(等等)。


-

Christopher Benson-Manica |我*应该*知道我在说什么 - 如果我

ataru(at)cyberspace.org |不,我需要知道。火焰欢迎。


Is it possible to write a macro (in unextended C89) such that

TEST( int, (1,2,3) );

expands to

int array[]={ 1,2,3 };

? I strongly suspect that it is not, but I don''t wish to overlook a
solution if one exists.

--
Christopher Benson-Manica | I *should* know what I''m talking about - if I
ataru(at)cyberspace.org | don''t, I need to know. Flames welcome.

解决方案



Christopher Benson-Manica wrote On 12/13/05 12:39,:

Is it possible to write a macro (in unextended C89) such that

TEST( int, (1,2,3) );

expands to

int array[]={ 1,2,3 };

? I strongly suspect that it is not, but I don''t wish to overlook a
solution if one exists.



#define TEST(type,list) type array[] = { list }

This seems pretty straightforward -- have I somehow
misread your question?

--
Er*********@sun.com



Eric Sosman wrote:

Christopher Benson-Manica wrote On 12/13/05 12:39,:

Is it possible to write a macro (in unextended C89) such that

TEST( int, (1,2,3) );

expands to

int array[]={ 1,2,3 };

? I strongly suspect that it is not, but I don''t wish to overlook a
solution if one exists.



#define TEST(type,list) type array[] = { list }

This seems pretty straightforward -- have I somehow
misread your question?

--
Er*********@sun.com



What about the parenthesis? I think he is trying to avoid C99 varargs
macros.

-David


David Resnick <ln********@gmail.com> wrote:

What about the parenthesis? I think he is trying to avoid C99 varargs
macros.



Yes, I am. I am dealing with a C++ implementation that does not
support the C99 varargs macros (among other things).

--
Christopher Benson-Manica | I *should* know what I''m talking about - if I
ataru(at)cyberspace.org | don''t, I need to know. Flames welcome.


这篇关于预处理器的可能性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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