#define和typedef的有趣功能,如果我错了,请纠正我 [英] Interesting features of #define and typedef, correct me if I am wrong
问题描述
看看这两个代码:
============================= ======
#define int_ptr int *
int_ptr a,b;
========== =========================
和
===================================
typedef int * int_ptr
int_ptr a,b;
================================ ===
在第一个例子中,只有a是一个指向整数的指针,但是b是一个
整数。
在第二个例子中,a,b都是指向整数的指针。
你们同意我的意见吗?
>
推荐答案
< fd ******* @ gmail.comwrote in message
<fd*******@gmail.comwrote in message
看看这两个代码:
================================ ===
#define int_ptr int *
int_ptr a,b;
============= ======================
和
=== ================================
typedef int * int_ptr
int_ptr a,b;
================== =================
在第一个例子中,只有a是指向整数的指针但b是
整数。
在第二个例子中,a,b都是指向整数的指针。
你们同意我的意见吗?
Look at these two codes:
===================================
#define int_ptr int*
int_ptr a, b;
===================================
and
===================================
typedef int* int_ptr
int_ptr a, b;
===================================
In first example, only a is a pointer-to-an-integer but b is an
integer.
At second example, both of a, b are pointer-to-an-integer.
Do you guys concur with me?
这是你需要typedef的原因之一。声明
指针的语法有点不寻常,虽然它在正式的语法分类中有意义
的方式。
That''s one of the reasons you need typedef. The syntax for declaring
pointers is a bit unusual, though it makes sense in a formal grammary sort
of way.
Malcolm McLean写道:
Malcolm McLean wrote:
< fd ******* @ gmail.comwrote in message
<fd*******@gmail.comwrote in message
>>看看这两个代码:
=========================== ========
#define int_ptr int *
int_ptr a,b;
==================== ===============
================== =================
typedef int * int_ptr
int_ptr a,b;
============ =======================
在第一个例子中,只有a是一个指向整数的指针,但b是一个
整数。
在第二个例子中,a,b都是指向整数的指针。
你们同意我的意见吗?/ >
这是你需要typedef的原因之一。声明
指针的语法有点不寻常,虽然它在正式的语法排序中有意义
的方式。
That''s one of the reasons you need typedef. The syntax for declaring
pointers is a bit unusual, though it makes sense in a formal grammary sort
of way.
这也是不为每行声明多个变量的好理由。
-
Ian Collins。
It''s also a good reason for not declaring more than one variable per line.
--
Ian Collins.
" Ian Collins" < ia ****** @ hotmail.comwrote in message
news:52 ************* @ mid.individual.net ...
"Ian Collins" <ia******@hotmail.comwrote in message
news:52*************@mid.individual.net...
Malcolm McLean写道:
Malcolm McLean wrote:
>< fd ******* @ gmail.comwrote在消息中
><fd*******@gmail.comwrote in message
[OP]
[OP]
> ;>
这是你需要typedef的原因之一。声明指针的语法有点不寻常,虽然它在正式的语法中是有意义的。
>>
That''s one of the reasons you need typedef. The syntax for declaring
pointers is a bit unusual, though it makes sense in a formal grammary
sort
of way.
这也是不为每行声明多个变量的一个很好的理由。
It''s also a good reason for not declaring more than one variable per line.
这篇文章是我不太了解的典型内容。它使用了C的成语来做一些不明智的事情。为什么?因为它的价值不明确且不必要。使用预处理器的东西和类型定义,当空格和回车符号自由地分隔
语句时,
世界是一个更好的地方。 #define语句的有趣之处在于定义内容的
内容,而不是语句本身。 LS
This post is typical of a variety that I don''t really understand. It uses
the idioms of C to do things that are ill-advised. Why? Because it''s
unclear and unnecessary. With preprocessor stuff and type definitions, the
world is a better place when whitespace and carriage return delimit the
statements liberally. What makes a #define statement interesting is the
content of what is being defined, not the statement itself. LS
这篇关于#define和typedef的有趣功能,如果我错了,请纠正我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!