实现sizeof运算符 [英] Implementing the sizeof operator

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

问题描述




有人最近要我实现sizeof运算符,即

写一个接受任何类型参数的函数,没有

使用sizeof运算符,应该能够以字节为单位返回内存中该数据类型所占用的大小

。谢谢:)


Abhishek Srivastava

Hi,

Somebody recently asked me to implement the sizeof operator, i.e. to
write a function that accepts a parameter of any type, and without
using the sizeof operator, should be able to return the size occupied
by that datatype in memory in bytes. Thanks :)

Abhishek Srivastava

推荐答案

* Abhishek Srivastava:
* Abhishek Srivastava:

>

有人最近要我实现sizeof运算符,即

写一个接受参数的函数任何类型,并且没有

使用sizeof运算符,应该能够以字节为单位返回内存中该数据类型所占用的大小

。谢谢:)
>
Somebody recently asked me to implement the sizeof operator, i.e. to
write a function that accepts a parameter of any type, and without
using the sizeof operator, should be able to return the size occupied
by that datatype in memory in bytes. Thanks :)



这听起来像家庭作业。


一个人必须希望没有人为你提供源代码(尽管他们

总是如此,以展示他们编写琐碎事物的能力。)


提示:数组。


- -

答:因为它弄乱了人们通常阅读文字的顺序。

问:为什么这么糟糕?

A:热门发布。

问:usenet和电子邮件中最烦人的事情是什么?

This sounds like HOMEWORK.

One must hope that nobody provides source code for you (although they
invariably do, to show off their ability to code trivial things).

Hint: array.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


Abhishek Srivastava写道:
Abhishek Srivastava wrote:




有人最近要我实现sizeof运算符,即

写一个接受任何类型参数的函数,并且没有

使用sizeof运算符,应该能够以字节为单位返回内存中该数据类型占用的大小。谢谢:)
Hi,

Somebody recently asked me to implement the sizeof operator, i.e. to
write a function that accepts a parameter of any type, and without
using the sizeof operator, should be able to return the size occupied
by that datatype in memory in bytes. Thanks :)



请注意,

数组的两个相邻元素之间的地址差异等于元素的大小。


Tom

Note that the difference in address between two adjacent elements of an
array is equal to the size of an element.

Tom


您好Alf P. Steinbach :)


这不是作业。只是想知道,因为我无法想到

解决方案。嗯....你的提示是使用数组,仍在思考

。非常感谢。


Alf P. Steinbach写道:
Hi Alf P. Steinbach :)

This is not homework. Just wanted to know because I couldn''t think of
the solution. Hmmmm.... your hint is to use an array, still pondering
over that. Thanks anyway.

Alf P. Steinbach wrote:

* Abhishek Srivastava:
* Abhishek Srivastava:


有人最近要我实现sizeof运算符,即

编写一个接受任何类型参数的函数,并且没有

使用sizeof运算符,应该能够以字节为单位返回内存中该数据类型所占用的大小

。谢谢:)

Somebody recently asked me to implement the sizeof operator, i.e. to
write a function that accepts a parameter of any type, and without
using the sizeof operator, should be able to return the size occupied
by that datatype in memory in bytes. Thanks :)



这听起来像家庭作业。


一个人必须希望没有人为你提供源代码(尽管他们

总是如此,以展示他们编写琐碎事物的能力。)


提示:数组。


- -

答:因为它弄乱了人们通常阅读文字的顺序。

问:为什么这么糟糕?

答:热门发布。

问:usenet和电子邮件中最烦人的事情是什么?


This sounds like HOMEWORK.

One must hope that nobody provides source code for you (although they
invariably do, to show off their ability to code trivial things).

Hint: array.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


这篇关于实现sizeof运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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