没有sizeof()的结构的大小 [英] Size of Stucture without sizeof()

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

问题描述

Hello All,


我想知道我们是否可以在不使用sizeof()的情况下知道结构的大小



任何提示。

解决方案

Robotnik写道:

Hello All,
我想知道我们是否可以在不使用sizeof()的情况下知道结构的大小。
任何提示。



否这也没有意义。这就是* for *的大小。各种不可移植的

技巧表明它们都是替代品,所有这些都是毫无价值的因为

它们是一种不可移植的技巧,当一个完全便携的替代品是

可用时:sizeof。


如果这是一项家庭作业,请告诉老师提出更好的

问题。


如果您有合理的需要知道C $ / $
计划之外的结构大小,您可以轻松编写一个小程序,其唯一目的是

测量结构并在某处写出结果。请注意,结果

取决于您的平台,编译器,您通过的选项以及可能的月亮阶段;你需要知道自己在做什么以及为什么要这样做。与现有二进制接口连接是一个可能的原因。

S.


Robotnik写道:

大家好,

我想知道我们是否可以在不使用sizeof()的情况下知道结构的大小。
任何提示。



提示:弄清楚。你会做出有意识的决定

以避免使用 - 操作符吗?还是`int''关键字?或者所有

出现的字母我?


关于你的问题:是的,有办法做到这一点。它b / b
是一种完全愚蠢的方式,不值得追求。如果你已经足够坚定了,你可以学会通过你的鼻孔啜饮Sauternes

,但这并不能很好地利用你的

鼻孔或Sauternes。


-

Eric Sosman
es ***** @ acm-dot-org.inva 盖子


2005年11月30日18:26:30 -0800,Robotnik < fa ********* @ gmail.com>

在comp.lang.c中写道:

Hello All,

我想知道我们是否可以在不使用sizeof()的情况下知道结构的大小。
任何提示。




否,我们 can''t。除了最病态的情况之外,我可以,但是你不能这么做。


-

Jack Klein

主页: http://JK-Technology.Com

常见问题解答

comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html

comp.lang.c ++ http://www.parashift.com/c++-faq-lite/

alt.comp.lang.learn.c-c ++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html


Hello All,

I want to know if we could know the size of a structyure
without the use of sizeof().
Any hints.

解决方案

Robotnik wrote:

Hello All,

I want to know if we could know the size of a structyure
without the use of sizeof().
Any hints.


No. Nor is that meaningful. That''s what sizeof is *for*. Various unportable
tricks suggest themselves as replacements, all of them worthless because
they''re unportable tricks when a perfectly portable alternative is
available: sizeof.

If this is a homework assignment, tell the instructor to come up with better
questions.

If you have a legitimate need to know the size of a structure outside of a C
program, you can easily write a small program whose sole purpose it is to
measure a struct and write the outcome somewhere. Note that the result
depends on your platform, your compiler, the options you passed and possibly
the phase of the moon; you need to know what you are doing and why you''re
doing it. Interfacing with existing binary interfaces is one possible reason.

S.


Robotnik wrote:

Hello All,

I want to know if we could know the size of a structyure
without the use of sizeof().
Any hints.



Hint: Get a clue. Would you make a conscious decision
to avoid the `-'' operator? Or the `int'' keyword? Or all
occurrences of the letter `i''?

As to your question: Yes, there is a way to do it. It
is an utterly silly way, and not worth pursuing. If you are
sufficiently determined, you can learn to sip Sauternes
through your nostrils, but that''s not a good use of your
nostrils or of the Sauternes.

--
Eric Sosman
es*****@acm-dot-org.invalid


On 30 Nov 2005 18:26:30 -0800, "Robotnik" <fa*********@gmail.com>
wrote in comp.lang.c:

Hello All,

I want to know if we could know the size of a structyure
without the use of sizeof().
Any hints.



No, "we" can''t. I can, in all but the most pathological cases, but
you can''t.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html


这篇关于没有sizeof()的结构的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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