473,324 Members | 2,370 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

What are anonymous objects?

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?

Nov 14 '05 #1
11 3256

G Fernandes wrote:
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.

Nov 14 '05 #2
On 9 Feb 2005 21:26:06 -0800, "G Fernandes" <ge**********@gmail.com>
wrote in comp.lang.c:

G Fernandes wrote:
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.


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
Nov 14 '05 #3
On 9 Feb 2005 21:20:42 -0800, "G Fernandes" <ge**********@gmail.com>
wrote in comp.lang.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?


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
Nov 14 '05 #4

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

G Fernandes wrote:
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.


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

Yes I know. Just wanted to prevent possible "this is not C++
newsgroup" response, because I really was asking a C question.

Nov 14 '05 #5
G Fernandes wrote:
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.
No.
There could be a pointer to it.

void* p = malloc(10);

The object to which p points doesn't have a name.

struct {
int I;
} x;

The type of the object named x doesn't have a name.
So what exactly are they?

Nov 14 '05 #6

On Thu, 9 Feb 2005, G Fernandes wrote:

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.


Not true. "Anonymous" means "nameless." But just because an object
has no name doesn't mean you can't access it. Consider:

int *foo(void)
{
int *p = malloc(sizeof *p);
return p;
}

'p' is a named object (namely, a pointer-to-int named 'p'). 'p' points
to an anonymous object; in other words, '*p' is an anonymous object.
Sure, you can refer to it as '*p', but that's not a "name" in this
sense. In this context, a "name" is just an identifier.
Repeat: '*p' is an anonymous object. So is the lvalue pointed to
by the return value of 'malloc(sizeof *p)'. So is '*foo()'.
It really is that simple! :)

-Arthur,
waiting for someone to contend that
it's not that simple after all
Nov 14 '05 #7
E. Robert Tisdale wrote:
G Fernandes wrote:
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.
No.
There could be a pointer to it.

void* p = malloc(10);


You could have used something other than void* so keep the focus on the
purpose and context of your statement, rather than introduce extra
"questions" in the minds of the OP or other curious readers.


The object to which p points doesn't have a name.

struct {
int I;
} x;

The type of the object named x doesn't have a name.
So what exactly are they?


Are you seriously saying x doesn't have a name? So what is 'x'?

A name of an object is the primary lvalue that comes alone with the
definition/declaration.
You defined a structure 'x', and you got a freebie lvalue 'x' for your
efforts. It's not anonymous!!!!!!!!!!!!!!!!!

Nov 14 '05 #8
In article <0m********************************@4ax.com>
Jack Klein <ja*******@spamcop.net> wrote:
There are two things that can be considered anonymous objects in C.

The first are string literals, both normal and wide. [snippage]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.


There is a third in C99: the objects created by compound literals.
You can (and in some cases, have to) take the address of one:

void f(void) {
const int *p = (const int []){1, 2, 3};
...
}

Here p points to the first of three "int"s in an array object, in
pretty much the same way that "cp" points to an anonymous array
created by a string literal in Jack Klein's example (which I snipped).
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 14 '05 #9
Luke Wu wrote:
E. Robert Tisdale wrote:
struct {
int I;
} x;

The type of the object named x doesn't have a name.


Are you seriously saying x doesn't have a name?


No, he's saying that the type of x doesn't have a name.

--
If geiger counter does not click,
the coffee, she is just not thick
Nov 14 '05 #10
Sebastian Hungerecker <se****@web.de> wrote:
Luke Wu wrote:
E. Robert Tisdale wrote:
struct {
int I;
} x;

The type of the object named x doesn't have a name.


Are you seriously saying x doesn't have a name?


No, he's saying that the type of x doesn't have a name.


The question was about anonymous objects. A type is not an object. x is
not an anonymous object; it is called x. Its type is anonymous, but that
is irrelevant to the question.

Richard
Nov 14 '05 #11
On 10 Feb 2005 06:18:32 GMT, Chris Torek <no****@torek.net> wrote in
comp.lang.c:
In article <0m********************************@4ax.com>
Jack Klein <ja*******@spamcop.net> wrote:
There are two things that can be considered anonymous objects in C.

The first are string literals, both normal and wide.

[snippage]
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.


There is a third in C99: the objects created by compound literals.
You can (and in some cases, have to) take the address of one:

void f(void) {
const int *p = (const int []){1, 2, 3};
...
}

Here p points to the first of three "int"s in an array object, in
pretty much the same way that "cp" points to an anonymous array
created by a string literal in Jack Klein's example (which I snipped).


Yes, you're absolutely right, I completely forgot them. Thanks.

Perhaps because one compiler that I do have that claims to support
that C99 feature crashed when I tried the feature. The compiler, that
is, not the executable, which was never produced. Not that I'm
complaining, it's a freeware compiler and does many things, including
many C99 features extremely well.

--
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
Nov 14 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
7
by: Michele Simionato | last post by:
So far, I have not installed Prothon, nor I have experience with Io, Self or other prototype-based languages. Still, from the discussion on the mailing list, I have got the strong impression that...
26
by: Steven Bethard | last post by:
I thought it might be useful to put the recent lambda threads into perspective a bit. I was wondering what lambda gets used for in "real" code, so I grepped my Python Lib directory. Here are some...
6
by: Mark Brandyberry | last post by:
I have a bit of a problem with an overloaded operator that I'm writing that I have distilled down to an example in the code below. Essentially, I have an operator function (+=) that takes a...
24
by: Romeo Colacitti | last post by:
Hi, Does anyone here have a strong understanding for the meanings of the terms "lvalue" and "rvalue" as it pertains to C, objects, and different contexts? If so please share. I've been...
59
by: Chris Dunaway | last post by:
The C# 3.0 spec (http://msdn.microsoft.com/vcsharp/future/) contains a feature called "Implicitly typed local variables". The type of the variable is determined at compile time based on the...
9
by: Brian Hampson | last post by:
I am trying to determine all the groups which the current user has permissions to add a member. Here's my code: foreach (System.DirectoryServices.SearchResult ADSearchres in...
6
by: Gaijinco | last post by:
I have always felt that there are a lot of topics that you learned the facts but you only grasp the matter sometime down the road. For me, two of those topics are inner classes and anonymous...
6
by: Bhuwan Bhaskar | last post by:
Hi, I want to know what is anonymas methods and how they can be used. Thanks and regards. Bhuwan
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.