define与typedef [英] define versus typedef

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

问题描述




#define和#define之间的区别是什么?和typedef?


A" #define"由预处理器处理并用作名称

substitude而typedef是一个新数据类型的声明

基于现有数据并由编译器处理。


所以,实际上两者都是等价的?或者是否有任何特殊的

案例,它会对使用哪个说明符产生影响?


问候,

克里斯

推荐答案



Christian Christmann写道:

Christian Christmann wrote:


什么是#define与#define之间的区别和typedef?

A" #define由预处理器处理并用作名称
substitude而typedef是基于现有数据类型的新数据类型的声明,由编译器处理。

所以,实际上两者都是等价的?


嗯,你自己在上面回答了这个问题。显然不同的野兽

一共。

或者是否有任何特殊情况会有所不同
使用哪个说明符?
Hi,

what is the difference between a "#define" and typedef?

A "#define" is handled by the preprocessor and serves as a name
substitude whereas "typedef" is a declaration of a new data type
based on an exisiting one and handled by a compiler.

So, actually both things are equivalent?
Well, you answered this yourself above. Obviously different beasts
altogether.
Or are there any special cases where it makes a difference
which specifier is used?




如果有人决定在你整齐的`#define`d new

类型上使用`#undef`,该怎么办?然后`#define将它视为完全不同的东西。在你的下面的一个

`#include`d文件中。没有告诉你。


`#define`多行类型可能很麻烦(想想`struct`和

`union`)。


我肯定有人会出现并指出其他差异,并且使用`#define`来定义新类型的缺陷。


Christian Christmann写道:
Christian Christmann wrote:


和#define之间的区别是什么?和typedef?


Typedef有一个类型,因此编译器可以强制执行类型检查。

Typedef可以在块或文件中作用域。一旦定义了#define

,它就必须是摆脱它,也就是说,当你没有自动取消时它不会是
留下一个块范围。 #defines可以很多

类型,如float,double,long,char,字符串,代码块等。我是

不确定typedef是否可以一个字符串,它肯定不是一个

宏(代码)。 #defines可以检查定义,typedef不能。

A" #define由预处理器处理并用作名称
substitude而typedef是基于现有数据类型的新数据类型的声明,由编译器处理。


是的。

那么,实际上两者都是等价的吗?或者是否有任何特殊的情况,它会使用哪个说明符?
Hi,

what is the difference between a "#define" and typedef?
Typedef''s have a type thus the compiler can enforce typechecking.
Typedefs can be scoped within blocks or files. Once a #define is
defined it must be undef''d to "get rid of it", that is, it doesn''t
automatically undef when you leave a block scope. #defines can be many
types like float, double, long, char, a string, code blocks, etc. I''m
not sure that a typedef can be a string and it certainly can''t be a
macro (code). #defines can be checked for definedness, typedefs cannot.
A "#define" is handled by the preprocessor and serves as a name
substitude whereas "typedef" is a declaration of a new data type
based on an exisiting one and handled by a compiler.
Yup.
So, actually both things are equivalent? Or are there any special
cases where it makes a difference which specifier is used?




说明符?是的,它有所不同,这取决于你想要什么




-

- Mark



Specifier? Yes it makes a difference and it depends on what you want to
do.

--
- Mark


Christian Christmann写道:
Christian Christmann wrote:
" #define"之间的区别是什么?和typedef?


一个是家庭作业问题,另一个是家庭作业问题。

A#define由预处理器处理并用作名称
substitude而typedef是基于现有数据类型的新数据类型的声明,由编译器处理。


有问题吗?答案!答案?问题!

所以,实际上两件事都是等价的?


不是远程的。一个人说声明这个标识符意味着这种类型,

并要求该类型格式正确并在当前范围内引入一个新名称

,所有这意味着加上该名称

可以用作一种类型。另一个说我在哪里写这个名字,假装

我写了这些代币而不是。

或者是否有任何特殊情况会产生影响
说明符?
what is the difference between a "#define" and typedef?
One is a homework question, and the other is a question for homework.
A "#define" is handled by the preprocessor and serves as a name
substitude whereas "typedef" is a declaration of a new data type
based on an exisiting one and handled by a compiler.
Questions? Answers! Answers? Questions!
So, actually both things are equivalent?
Not remotely. One says "declare that this identifier means this type",
and requires that the type is well-formed and introduces a new name
into the current scope, with all that that implies plus that name
can be used as a type. The other says "where I write this name, pretend
I wrote these tokens instead".
Or are there any special cases where it makes a difference which
specifier is used?




[只有其中一个是说明符。]


有很多/一般/它会产生影响的情况。


-

Chris" defined" Dollin

我们没时间找到我们想知道的一切。 /钹的冲突/



[Only one of them is a specifier.]

There are lots of /general/ cases where it makes a difference.

--
Chris "defined" Dollin
"We did not have time to find out everything we wanted to know." /A Clash of Cymbals/


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

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