是的typedef和#定义同在C? [英] Are typedef and #define the same in c?

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

问题描述

我不知道是否的typedef 的#define 在同一个的 C类=标签后称号=显示问题C

I wonder if typedef and #define are the same in c?

推荐答案

没有。

的#define 为preprocessor令牌:编译器本身将永远不会看到它

的typedef 是一个编译器标记:在preprocessor不关心它

#define is a preprocessor token: the compiler itself will never see it.
typedef is a compiler token: the preprocessor does not care about it.

您可以使用一个或另一个来达到同样的效果,但最好使用适合您需求的适当的一个

You can use one or the other to achieve the same effect, but it's better to use the proper one for your needs

#define MY_TYPE int
typedef int My_Type;

当事情变得毛茸茸,使用正确的工具,使得它正确

When things get "hairy", using the proper tool makes it right

#define FX_TYPE void (*)(int)
typedef void (*stdfx)(int);

void fx_typ(stdfx fx); /* ok */
void fx_def(FX_TYPE fx); /* error */

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

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