本文介绍了关于typedef和宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我注意到typedef正在做的事情可以通过 宏完成,我也认为必须有一个特定的理由来说明为什么 typedef介绍了, 究竟有什么区别,有什么原因我们应该优先考虑更喜欢一个而不是另外一个是什么? I noticed that what is being done by typedef can very much be done bymacro, and i also think there must be a specific reason as to whytypedef was introduced,what is the exact difference, and are there any reasons that we shouldprefer 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, butyou should prefer macros when you want pp-token substitution to occur. The internal implementation of typedef is up to the implementor. There IsMore Than One Way To Do It. --Richard Heathfield"Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.ukemail: rjh at the above domain, - www. typedef是一种合适的类型。宏是文本替换。可能 看起来并不是很大的区别在于typedef int number和#define number int,但你试试这个: #define pointer1 int * typedef int * pointer2; pointer1 a,b; pointer2 c,d; b $ b多少指针? Richard A typedef is a proper type. A macro is a text substitution. There maynot seem to be much difference between typedef int number and #definenumber int, but you try this: #define pointer1 int *typedef int * pointer2; pointer1 a, b;pointer2 c, d; How many pointers? Richard [...] 对于某些正确的值。 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 anexisting 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和宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-21 10:52