什么是匿名对象? [英] What are anonymous objects?

查看:91
本文介绍了什么是匿名对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听到过一些提及匿名的内容。在c.l.c和其他地方的对象

(对话),我想知道究竟是什么。匿名

似乎暗示没有名字,但没有名字暗示一个

无法访问该对象,这意味着该对象将是

无用。


他们究竟是什么?

I''ve heard some mention "anonymous" objects in c.l.c and other places
(conversations), and I was wondering what exactly these are. Anonymous
seems to imply that there is no name, but no name implies that one
can''t access the object, which implies that the object would be
useless.

So what exactly are they?

推荐答案



G Fernandes写道:

G Fernandes wrote:
我听说过一些提及匿名的内容。 c.l.c和其他地方的对象
(对话),我想知道这些是什么。
Anonymous似乎暗示没有名字,但没有名字暗示一个人无法访问该对象,这意味着该对象将无用。
<那么它们究竟是什么?
I''ve heard some mention "anonymous" objects in c.l.c and other places
(conversations), and I was wondering what exactly these are. Anonymous seems to imply that there is no name, but no name implies that one
can''t access the object, which implies that the object would be
useless.

So what exactly are they?




只是想补充一点,我对于与

类相关的对象并不感到困惑,我在谈论变量之类的对象。



Just wanted to add that I''m not confused about objects associated with
classes, I''m talking about objects like variables.


2005年2月9日21:26:06 -0800,G Fernandes < ge ********** @ gmail.com>

在comp.lang.c中写道:
On 9 Feb 2005 21:26:06 -0800, "G Fernandes" <ge**********@gmail.com>
wrote in comp.lang.c:

G Fernandes写道:

G Fernandes wrote:
我听说过一些提及匿名的内容。 clc和其他地方的对象
(对话),我想知道这些是什么。
I''ve heard some mention "anonymous" objects in c.l.c and other places
(conversations), and I was wondering what exactly these are.


Anonymous


Anonymous

似乎暗示没有名字,但是没有名字暗示一个人无法访问该对象,这意味着该对象将无用。

那究竟是什么?
seems to imply that there is no name, but no name implies that one
can''t access the object, which implies that the object would be
useless.

So what exactly are they?



只是想补充一点,我不会对与
类相关的对象感到困惑,我在谈论像变量这样的对象。



Just wanted to add that I''m not confused about objects associated with
classes, I''m talking about objects like variables.




那很好,因为C里没有课。


-

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



That''s good, because there are no classes in C.

--
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


2005年2月9日21:20 :42 -0800,G Fernandes < ge ********** @ gmail.com>

在comp.lang.c中写道:
On 9 Feb 2005 21:20:42 -0800, "G Fernandes" <ge**********@gmail.com>
wrote in comp.lang.c:
我已经听到一些提及匿名的c.l.c和其他地方的对象
(对话),我想知道这些是什么。匿名
似乎暗示没有名字,但没有名字暗示一个人无法访问该对象,这意味着该对象将无用。
<那么究竟是什么呢?
I''ve heard some mention "anonymous" objects in c.l.c and other places
(conversations), and I was wondering what exactly these are. Anonymous
seems to imply that there is no name, but no name implies that one
can''t access the object, which implies that the object would be
useless.

So what exactly are they?




有两件事可以被认为是C中的匿名对象。


第一个是正常和广泛的字符串文字。


在规范的C程序中:


#include< stdio.h>

int main(无效)

{

printf(" Hello,World!\ n");

返回0;

}


字符串文字Hello,World \ n,肯定是一个对象,在
$中b $ b其实它是一个包含14个字符的数组,包括最后的''\ 0'',

但它没有名字。


同样:


char * cp ="字符串文字;


此字符串文字也没有名称,但可以访问来自许多人
程序中的不同位置,声明在范围内的地方

以及cp可能作为参数传递的任何地方。指针

有一个名称,它指向的对象没有。


另一种可能会或可能不会被称为匿名对象的情况 C中的
是对象强加的对象。动态分配的内存。这是
并不是真的一样,但由于这个术语不是由C

标准定义的,你可以延长这一点。


考虑:


struct anon {int x;双y;长z;接下来的代码:


struct anon * ap = malloc(sizeof * ap);

假设malloc()成功,一旦你实际分配了一个值为

ap-> x,ap-> y或ap-> z中的任何一个或全部,那块内存占用了b
的有效类型,虽然从技术上来说它实际上并不是
一个struct anon对象。


-

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



There are two things that can be considered anonymous objects in C.

The first are string literals, both normal and wide.

In the canonical C program:

#include <stdio.h>
int main(void)
{
printf("Hello, World!\n");
return 0;
}

The string literal "Hello, World\n", is most certainly an object, in
fact it is an array of 14 characters, including the ''\0'' at the end,
but it has no name.

Likewise:

char *cp = "A string literal";

This string literal has no name either, yet can be accessed from many
different places in a program, both where the declaration is in scope
and any place where cp might be passed as an argument. The pointer
has a name, the object it points to does not.

The other case of what might or might not be called anonymous objects
in C are objects "imposed" on dynamically allocated memory. This is
not really the same thing, but since the term is not defined by the C
standard, you could stretch the point.

Consider:

struct anon { int x; double y; long z; };

Then later in code:

struct anon *ap = malloc(sizeof *ap);

Assuming the malloc() succeeds, once you actually assign a value to
any or all of ap->x, ap->y, or ap->z, that block of memory takes on
the effective type of a struct anon, although technically it is not
actually a struct anon object.

--
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


这篇关于什么是匿名对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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