我怎样才能模拟sizeof() [英] How can i emulate sizeof()

查看:106
本文介绍了我怎样才能模拟sizeof()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我怎样才能为整数模拟sizeof()


解决方案

Eugeny Myunster写道:


大家好,

我如何模拟sizeof()

只对整数?



你可以查看sizeof,按照你的例子中的例子

和goings and doings,寻求永远忠实于它的教义,并且

在各种方面不断努力模拟自己的行为

of sizeof。在任何进退两难的情况下,问问自己大小会做什么?

不要接受简单的警察答案(尺寸不会这样,在

之后所有),但要激励自己更深入,更诚实的自我检查。

喂饱饥饿的人,治愈病人,慷慨地给穷人 -

短[* ],模拟sizeof。

[*]一种指定的整数。


-
Er ********* @ sun.com


< blockquote> Eugeny Myunster写道:


>

Hello all,

我如何模拟sizeof()

仅适用于整数?



我真的很想知道哪位教师继续完成这项任务。


你为什么要这样做?模拟sizeof",当sizeof存在时只是为了这个

目的?


如何


#define MySizeof(x)sizeof(x)


现在你可以模拟sizeof例如,使用MySizeof(int)。


-

+ ------------- ------------ + -------------------- + ---------------- ------- +

| Kenneth J. Brody | www.hvcomputer.com | #include |

| kenbrody / at\spamcop.net | www.fptech.com | < std_disclaimer.h |

+ ------------------------- + --------- ----------- + ----------------------- +

不要 - 邮寄给我:< mailto:Th ************* @ gmail.com>


Kenneth Brody< ke******@spamcop.netwrites:


Eugeny Myunster写道:


> >
大家好,
我如何只为整数模拟sizeof()



我真的很想知道哪位教师继续完成这项任务。


你为什么要这样做?模拟sizeof",当sizeof存在时只是为了这个

目的?


如何


#define MySizeof(x)sizeof(x)


现在你可以模拟sizeof例如,通过使用MySizeof(int)。



除了sizeof运算符之外,宏需要一个

括号参数;你不能写MySizeof 42。


我会用:


#define MySizeof sizeof


这同样有用(即根本没用)。


对原始海报的认真回答:你为什么要这样做? />
有一些方法可以在不使用

sizeof运算符的情况下确定对象的大小,但使用它们没有意义; sizeof

运营商就是为了这个目的而存在的。


问:我怎么砸钉子?我不想用锤子。

A:无论如何要用锤子;这就是它的用途。


话虽如此,作为一项练习并不是完全没有意义*。

搞清楚如何在不使用sizeof的情况下计算某些东西的大小

确实提供了一个机会来证明你理解该语言的某些方面。由此产生的代码片段本身并不是很有用,但是经典的hello,world

程序也不是很有用。如果我真的想要打印你好,世界在stdout上,我会用

echo。 (例如,有一个GNUhello程序,但它只是作为一个演示而存在

;它实际上并没有用。)那只是自然界

的家庭作业。


哦,谈到家庭作业:做你自己。如果我们给你答案,你会学到什么?b
如果您自己尝试自己,我们愿意提供

提示,但如果您希望我们为您解决

问题,请告诉我们您的导师'的电子邮件地址,我们

可以直接提交我们的解决方案。


-

Keith Thompson(The_Other_Keith)< ; ks *** @ mib.org>

诺基亚

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

- Antony Jay和Jonathan Lynn,是部长


Hello all,
How can i emulate sizeof()
only for integers?

解决方案

Eugeny Myunster wrote:

Hello all,
How can i emulate sizeof()
only for integers?

You can look up to sizeof, follow its example in your comings
and goings and doings, seek always to be true to its teachings, and
strive unceasingly in all ways to model your own behavior after that
of sizeof. In any dilemma, ask yourself "What would sizeof do?"
Don''t accept easy, cop-out answers (sizeof would not do so, after
all), but spur yourself to deeper and more honest self-examination.
Feed the hungry, heal the sick, give generously to the poor -- in
short[*], emulate sizeof.
[*] A kind of integer, as specified.

--
Er*********@sun.com


Eugeny Myunster wrote:

>
Hello all,
How can i emulate sizeof()
only for integers?

I''d really love to know which instructors keep giving this assignment.

Why do you want to "emulate sizeof", when sizeof exists just for this
purpose?

How about:

#define MySizeof(x) sizeof(x)

Now you can "emulate sizeof" by using "MySizeof(int)", for example.

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don''t e-mail me at: <mailto:Th*************@gmail.com>


Kenneth Brody <ke******@spamcop.netwrites:

Eugeny Myunster wrote:

>>
Hello all,
How can i emulate sizeof()
only for integers?


I''d really love to know which instructors keep giving this assignment.

Why do you want to "emulate sizeof", when sizeof exists just for this
purpose?

How about:

#define MySizeof(x) sizeof(x)

Now you can "emulate sizeof" by using "MySizeof(int)", for example.

Except that the macro, unlike the sizeof operator, requires a
parenthesized argument; you can''t write "MySizeof 42".

I''d use:

#define MySizeof sizeof

which is equally useful (i.e., not at all).

A serious answer to the original poster: Why do you want to do this?
There are ways to determine the size of an object without using the
sizeof operator, but there''s no point in using them; the sizeof
operator exists for exactly this purpose.

Q: How do I pound in a nail? I don''t want to use a hammer.
A: Use a hammer anyway; that''s what it''s for.

Having said that, it''s not entirely pointless *as an exercise*.
Figuring out how to compute the size of something without using sizeof
does present an opportunity to demonstrate that you understand certain
aspects of the language. The resulting piece of code isn''t going to
be useful in itself, but then neither is the classic "hello, world"
program; if I really want to print "hello, world" on stdout, I''ll use
echo. (There''s a GNU "hello" program, for example, but it exists
purely as a demo; it''s not actually useful.) That''s just the nature
of homework assignments.

Oh, and speaking of homework assignments: DO IT YOURSELF. What will
you learn if we just give you the answer? We''re willing to offer
hints if you try to do it yourself, but if you want us to solve the
problem for you, please give us your instructor''s e-mail address so we
can submit our solutions directly.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"


这篇关于我怎样才能模拟sizeof()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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