关于typedef和宏 [英] Regarding typedef and macro

查看:91
本文介绍了关于typedef和宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到typedef正在做的事情可以通过

宏完成,我也认为必须有一个特定的理由来说明为什么

typedef介绍了,

究竟有什么区别,有什么原因我们应该优先考虑
更喜欢一个而不是另外一个是什么?

I noticed that what is being done by typedef can very much be done by
macro, and i also think there must be a specific reason as to why
typedef was introduced,
what is the exact difference, and are there any reasons that we should
prefer one over the other and how is typedef internally implemented?

推荐答案

sa ***** @ yahoo。 co.in 说:

我注意到typedef正在做的事情可以通过

宏完成,而且我也认为必须有一个特定的原因,为什么

typedef被引入,

究竟是什么区别,有什么理由我们应该

更喜欢一个而不是另一个并且typedef在内部如何实现?
I noticed that what is being done by typedef can very much be done by
macro, and i also think there must be a specific reason as to why
typedef was introduced,
what is the exact difference, and are there any reasons that we should
prefer one over the other and how is typedef internally implemented?



确切的区别是typedef为现有类型创建一个同义词,

而宏会导致pp-token替换发生。 />

当你想要现有类型的同义词时,你应该更喜欢typedef,但是当你想要进行pp-token替换时,你应该更喜欢宏。


typedef的内部实现取决于实现者。还有

不止一种方式。


-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上述域名中, - www。

The exact difference is that typedef creates a synonym for an existing type,
whereas macros cause pp-token substitution to occur.

You should prefer typedef when you want a synonym for an existing type, but
you should prefer macros when you want pp-token substitution to occur.

The internal implementation of typedef is up to the implementor. There Is
More Than One Way To Do It.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.


sa ***** @ yahoo.co.in 写道:
sa*****@yahoo.co.in wrote:

我注意到正在做什么通过typedef可以通过

宏来完成,我也认为必须有一个特定的原因,为什么

typedef被引入,

有什么确切的区别,有什么理由我们应该b $ b更喜欢一个而不是另一个并且typedef在内部如何实现?
I noticed that what is being done by typedef can very much be done by
macro, and i also think there must be a specific reason as to why
typedef was introduced,
what is the exact difference, and are there any reasons that we should
prefer one over the other and how is typedef internally implemented?



typedef是一种合适的类型。宏是文本替换。可能

看起来并不是很大的区别在于typedef int number和#define

number int,但你试试这个:


#define pointer1 int *

typedef int * pointer2;


pointer1 a,b;

pointer2 c,d; < br $> b $ b多少指针?

Richard

A typedef is a proper type. A macro is a text substitution. There may
not seem to be much difference between typedef int number and #define
number int, but you try this:

#define pointer1 int *
typedef int * pointer2;

pointer1 a, b;
pointer2 c, d;

How many pointers?

Richard


rl *@hoekstra-uitgeverij.nl (Richard Bos)写道:

[...]
rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
[...]

typedef是一种合适的类型。
A typedef is a proper type.



[...]


对于某些正确的值。 typedef为

现有类型创建别名;它没有创造新类型。


-

Keith Thompson(The_Other_Keith) ks *** @ mib.org < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *< http: //users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。

[...]

For certain values of "proper". A typedef creates an alias for an
existing type; it doesn''t create a new type.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


这篇关于关于typedef和宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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