473,569 Members | 2,759 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C objects

What is a C object ?

If i have some function "func()" in my C program, then
can i say that "func()" is a C object ?
or if i have some function pointer (ptr) which contains the address
of function "func()", can i say that ptr is pointing to some C object ?

Is a C object always associated with some "data" ?

thanx in advance for any help .....
Nov 14 '05
115 4822


E. Robert Tisdale wrote:
Mike Wahler wrote:
E. Robert Tisdale wrote:
A data object must be initialized to a valid value
of an object of that type before you can call it an object --

Not true.
it must be constructed.

"Constructe d" doesn't have a meaning in C.

int main(int argc, char* argv[]) {
int i; // is 'i' an object? The language standard says it is
return 0;
}

Whatever value 'i' has must be a valid int.

typedef struct X {
int* p;
} X;

int main(int argc, char* argv[]) {
X x; // is 'x' a valid object?
return 0;
}


Sure, X is a valid object; it is a structure containing a pointer.
Since it is never used, the compiler may choose to optimize it
away, but as far as your source code is concerned, it is a real thing.

--
Ron Collins
Air Defense/RTSC/BCS
"I have a plan so cunning, you could put a tail on it and call it a weasel"

Nov 14 '05 #21
E. Robert Tisdale wrote:

Keith Thompson wrote:
E. Robert Tisdale writes:
pete wrote:

junky_fell ow wrote:
>Is a C object always associated with some "data"?

Normally, yes, though I suppose you could malloc some memory and
free it immediately if you wanted to, without involving any data.

No.

malloc() doesn't create objects.
It returns a pointer of type void*.
A data object must be initialized to a valid value
of an object of that type before you can call it an object --
it must be constructed.

C99 3.14 defines the term "object":

object

region of data storage in the execution environment,
the contents of which can represent values

The term "object" refers to the *region*,
not to the data it may contain.


It *must* be an object of some type.
The type specifies *all* of the values that that object may have.


Keith Thompson is right and you are completely wrong.

N869
6.2.5 Types
[#1] The meaning of a value stored in an object or returned
by a function is determined by the type of the expression
used to access it. (An identifier declared to be an object
is the simplest such expression; the type is specified in
the declaration of the identifier.)

If you have
signed char Integer = -1;
then Integer is less than zero.
but (*(unsigned char *)&Integer) is a positive value
and there's only one object under discusion there.
The statement
--*(unsigned char *)&Integer;
decrements an object of type unsigned char.
Nov 14 '05 #22

"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > wrote in message
news:cf******** **@nntp1.jpl.na sa.gov...
Mike Wahler wrote:
E. Robert Tisdale wrote:
A data object must be initialized to a valid value
of an object of that type before you can call it an object --
Not true.
it must be constructed.


"Constructe d" doesn't have a meaning in C.

int main(int argc, char* argv[]) {
int i; // is 'i' an object? The language standard says it is
return 0;
}


Whatever value 'i' has must be a valid int.


Right. But 'i' isn't required to represent a value.
That's what 'uninitialized' means.

typedef struct X {
int* p;
} X;

int main(int argc, char* argv[]) {
X x; // is 'x' a valid object?


Yes. But it doesn't represent any meaningful value.

-Mike

Nov 14 '05 #23

"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > wrote in message
news:cf******** **@nntp1.jpl.na sa.gov...
Keith Thompson wrote:
E. Robert Tisdale writes:
pete wrote:

junky_fell ow wrote:
>Is a C object always associated with some "data"?

Normally, yes, though I suppose you could malloc some memory and
free it immediately if you wanted to, without involving any data.

No.

malloc() doesn't create objects.
It returns a pointer of type void*.
A data object must be initialized to a valid value
of an object of that type before you can call it an object --
it must be constructed.

C99 3.14 defines the term "object":

object

region of data storage in the execution environment,
the contents of which can represent values

The term "object" refers to the *region*,
not to the data it may contain.


It *must* be an object of some type.
The type specifies *all* of the values that that object may have.


Note that it's. "May", not "must". Verbatim from the standard:
"can represent values." When the standard means "must", it
says "must". Here, it does not.

-Mike
Nov 14 '05 #24


Stefan Ram wrote:
RCollins <rc***@nospam.t heriver.com> writes:
So, by this reasoning, then the 2 functions (in the same source
file) below:
void foo(void) {
int i;
i = 1;
}
void bar(void) {
int i;
i = 2;
}
define only 1 identifier, that happens to have 2 different
object locations?

Yes, just let me quote ISO/IEC 9899:1999 (E):

"For each different entity that an identifier designates,
the identifier is visible (i.e., can be used) only
within a region of program text called its scope."

^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^

Notice the part that I underlined. This would tell me that the
var i inside foo() is different than the var i inside bar(); they
just happen to have the same name.

Note the singular "an identifier". "An identifier" (i.e., only
1 identifier) might designate different entities. This is the
wording of ISO/IEC 9899:1999 (E).

Another reason: An identifier is a lexical concept and is
defined as:

(6.4.2.1) identifier:
identifier-nondigit
identifier identifier-nondigit
identifier digit

So by this extensional definition, there exist only one
identifier "i".
This is just a rule on how to spell identifiers. Let me put this
another way: if I generate a lexical parse tree for the 2 functions
foo() and bar() above, would you expect that the var i appears only
once?

I don't think we're on the same wavelength at all. We're (or, at
least, I) are not talking about what happens at run-time. We're
talking about source code (the only part we have any real control
over).

The source code model does not contain the notion of an
"object". The source code is built of lexical and syntactical
units. An object is part of the execution model, though in
order to interpret (make sense of) the source code, one needs
to mention execution model entities.

in the simple function:
void foo(void) {
int i;
}
the identifer i refers to an object of type integer; if I never use
the variable, or if foo() is explicitly never called, then the
compiler may choose to optimize it away. But, as far as my (source)
program is concerned, both foo() and i exist, and refer to somthing
concrete.

This is not a mere "optimizati on". The local variables of a
function are created as many times as the function is
activated at run time - otherwise recursion would not work.
So, if a function is not activated, there is not reason to
create activation records.


Yes, but what has this to do with identifiers or object names?
For the most part, I would not expect an identifier to survive
the compiler ... only references to stack or memory locations.
(There are exceptions, of course, especially if you are generating
debugging code).

The identifier "i" refers to an object under the assumption
that the function is currently activated. This is usually
taken for granted, so that one does not mention it. By
recursion, a function may be activated more than once in the
same program instance at the same time. In this case, when one
speaks about "i" one usually is referring to an exemplary i
from all those is existing at the same time.


So, then, each time a function is called (recursive or not),
you get a new object named "i" (for example) that is different
than any other object named "i".

I think this is what I started out saying several posts ago.

--
Ron Collins
Air Defense/RTSC/BCS
"I have a plan so cunning, you could put a tail on it and call it a weasel"

Nov 14 '05 #25
E. Robert Tisdale wrote:
Keith Thompson wrote:
E. Robert Tisdale writes:
pete wrote:

junky_fellow wrote:
> Is a C object always associated with some "data"?
Normally, yes, though I suppose you could malloc some memory and
free it immediately if you wanted to, without involving any data.
No.

malloc() doesn't create objects.
It returns a pointer of type void*.
A data object must be initialized to a valid value
of an object of that type before you can call it an object --
it must be constructed.


C99 3.14 defines the term "object":

object
region of data storage in the execution environment,
the contents of which can represent values

The term "object" refers to the *region*, not to the data it may contain.

It *must* be an object of some type.
The type specifies *all* of the values that that object may have.


Please Mr. Tisdale, consider this ..

unsigned int *ui;
ui = malloc(sizeof *ui);

.... Assuming malloc() was successful, is ui[0] an object? Of course
it is. Was it created by the declaration of ui? No, declarations
don't define or create objects. I guess malloc() did it.
--
Joe Wright mailto:jo****** **@comcast.net
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 14 '05 #26
Joe Wright wrote on 08/08/04 :
unsigned int *ui;
This is the defintion of a pointer. It creates statically a 'pointer'
object. Its value is undeterminate (points anywhere).
ui = malloc(sizeof *ui);
This creates dynamically an object which address is stored into the
pointer 'ui'.
... Assuming malloc() was successful, is ui[0] an object? Of course it is.
Yes.
Was it created by the declaration of ui?
What declaration ?
No, declarations don't define or
create objects. I guess malloc() did it.


I think you are mixing declaration and definition. Of course an object
declaration creates nothing, but an object definition does create an
object.

The point is that a pointer is just a few bytes in memory, but it has a
size, type and address. It is an object.

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html

"C is a sharp tool"

Nov 14 '05 #27
A note to Stefan Ram:

You indent all your new text. Please don't do this; it's confusing.
Indentation usually indicates that you're quoting someone else. New
text should be left-justified, like this.

Thank you.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #28
Mike Wahler wrote:
E. Robert Tisdale wrote:
Mike Wahler wrote:
E. Robert Tisdale wrote:

A data object must be initialized to a valid value
of an object of that type before you can call it an object --

Not true.

it must be constructed.

"Constructed " doesn't have a meaning in C.

int main(int argc, char* argv[]) {
int i; // is 'i' an object? The language standard says it is
return 0;
}


Whatever value 'i' has must be a valid int.


Right. But 'i' isn't required to represent a value.
That's what 'uninitialized' means.
typedef struct X {
int* p;
} X;

int main(int argc, char* argv[]) {
X x; // is 'x' a valid object?


Yes. But it doesn't represent any meaningful value.


Then your definition of *type* makes no sense.
A type defines *all* of the values that an object may have.
You seem to be saying that an "uninitiali zed" object
may have [redundant] meaningless values.
By your definition, the values that a type may have
is determined by its representation
which means that data abstraction is not possible in C.

You are interpreting the C standards documents too literally.
And just like the fundamentalists
who interpret Holy Scripture too literally,
you eventually encounter contradictions to logic and common sense.
Nov 14 '05 #29


Stefan Ram wrote:
RCollins <rc***@nospam.t heriver.com> writes:
"For each different entity that an identifier designates,
the identifier is visible (i.e., can be used) only
within a region of program text called its scope."


^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^
Notice the part that I underlined. This would tell me that the
var i inside foo() is different than the var i inside bar(); they
just happen to have the same name.

As it has been noticed before, "var" is an informal term in C,
so you might use it this way. The notion "the var i" is not
the same notion as the notion "the identifier i", because the
meaning of "identifier " is defined by ISO/IEC 9899:1999 (E).

(6.4.2.1) identifier:
identifier-nondigit
identifier identifier-nondigit
identifier digit


This is just a rule on how to spell identifiers. Let me put this
another way: if I generate a lexical parse tree for the 2 functions
foo() and bar() above, would you expect that the var i appears only
once?

It is possible that the text "i" is stored only once in the
memory of the parser, when the parse tree actually is a direct
acyclic graph. This is an implementation detail of a parser.

This is not a mere "optimizati on". The local variables of a
function are created as many times as the function is
activated at run time - otherwise recursion would not work.
So, if a function is not activated, there is not reason to
create activation records.


Yes, but what has this to do with identifiers or object names?

It has only to do with identifieres as long as the source
code is taken into consideration.

For the most part, I would not expect an identifier to survive
the compiler ... only references to stack or memory locations.
(There are exceptions, of course, especially if you are generating
debugging code).


(...)
So, then, each time a function is called (recursive or not),
you get a new object named "i" (for example) that is different
than any other object named "i".

Independend of the language "C", the identifier "i" and the
meaning of "object": it is part of the meaning of the word
"other", that any object is different than any /other/ object.

What remains is: A single identifier of the source code might
refer to several objects at run time, either by multiple
scopes, or by multiple life-times, or by both.


While I appreciate your obvious knowledge (and it *is* vast),
I have completely lost track of where *you* stand in all this.

Let me summarize my position:
Across different scopes (or different lifetimes) there may be
multiple objects (variables?) with the same identifier name.
These objects are separate and distinct from each other; the
mere fact that multiple objects have the same identifier name does
not make them the same object. In addition, I feel that an
identifier name declared in two different functions declares two
different identifiers. IOW, the "i" in foo() is a *different*
identifier than the "i" in bar(). (In other languages, this
would be explicitly called out by the full identifier of foo::i
or bar::i). So long as the compiler can tell the difference,
I don't really care how the run-time environment stores them
(or even *if* it stores them).

Now ... what was *your* position again?

--
Ron Collins
Air Defense/RTSC/BCS
"I have a plan so cunning, you could put a tail on it and call it a weasel"

Nov 14 '05 #30

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

Similar topics

2
8240
by: dasod | last post by:
I would like to know if my method to remove list objects is correct in this small test program. It seems to me that there might be a simplier way, but I'm afraid I don't know enough about list iterators and how they are behaving in situations like this. #include <iostream> #include <list> class Test; typedef std::list< Test* > Tlist;
9
1871
by: Aguilar, James | last post by:
Hey guys. A new question: I want to use an STL libarary to hold a bunch of objects I create. Actually, it will hold references to the objects, but that's beside the point, for the most part. Here's the question: I want to be able to change the references (including deleting them). Is there any way to do that besides using pointers rather...
6
2560
by: Alfonso Morra | last post by:
I have written the following code, to test the concept of storing objects in a vector. I encounter two run time errors: 1). myClass gets destructed when pushed onto the vector 2). Prog throws a "SEGV" when run (presumably - attempt to delete deleted memory. Please take a look and see if you can notice any mistakes I'm making. Basically,...
3
3018
by: ytrewq | last post by:
Should dynamic ("expando") properties be restricted to native and user-defined objects? Or should host objects - such as references to the browser or a plug-in or to the document and its elements - also allow them? Adding (and removing) object properties dynamically is an acceptable and common practice in JavaScript, and greatly adds to the...
8
1849
by: Lüpher Cypher | last post by:
Hi, Suppose we have a hierarchical class structure that looks something like this: Object | +-- Main | +-- Object1
161
7753
by: KraftDiner | last post by:
I was under the assumption that everything in python was a refrence... so if I code this: lst = for i in lst: if i==2: i = 4 print lst I though the contents of lst would be modified.. (After reading that
7
8208
by: Jo | last post by:
Hi, How can i differentiate between static and dynamic allocated objects? For example: void SomeFunction1() { CObject *objectp = new CObject; CObject object;
21
2192
by: George Exarchakos | last post by:
Hi everyone, I'd like your help... Can we have a std::list<BASEwhere BASE be the base class of a class hierarchy? I want to add to this list objects that are inherited from BASE class but not necessarily the same... class base { int x;
27
2530
by: SasQ | last post by:
Hello. I wonder if literal constants are objects, or they're only "naked" values not contained in any object? I have read that literal constants may not to be allocated by the compiler. If the Standard is saying that "object is a region of storage", I deduce from that that literal constants aren't objects because they may not be alocated...
14
5989
by: Jess | last post by:
Hello, I learned that there are five kinds of static objects, namely 1. global objects 2. object defined in namespace scope 3. object declared static instead classes 4. objects declared static inside functions (i.e. local static objects) 5. objects declared at file scope.
0
7698
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8122
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7673
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7970
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1213
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.