C objects

J

junky_fellow

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

pete

junky_fellow said:
What is a C object ?

N869
3.15
[#1] object
region of data storage in the execution environment, the
contents of which can represent values
If i have some function "func()" in my C program, then
can i say that "func()" is a C object ?
No.

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 ?
No.

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.

Examples of objects are:
local variables,
external variables,
the memory returned by malloc and friends,
and string literals in a pointer context, refer to objects

When accessed by an identifier of object type,
objects can contain values.
The sizes of various types defined by the language,
are implementation defined.

Functions are not objects. The standard doesn't say very much
about how functions are represented in memory.
The address, is the only addressable byte of a function.
You don't know anything about how the rest of the function
resides in memory.
The sizeof operation is not defined for functions.
 
K

Keith Thompson

Mabden said:
C has objects? When did that happen?!

Boy I have GOT to get one of these new "standards" gizmos...

Yes, C has objects. (They have nothing to do with what's commonly
called "object-oriented programming".)
 
E

Emmanuel Delahaye

junky_fellow wrote on 07/08/04 :
What is a C object ?

A variable.
If i have some function "func()" in my C program, then
can i say that "func()" is a C object ?
Nope.

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 ?
Nope.

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

It *is* data.
 
S

Stefan Ram

Emmanuel Delahaye said:
A variable.

An object is a region of data storage in the execution
environment (3.14).

A variable is an identifier for an object introduced by a
declaration.

An object does not need to have a variable.
 
J

Jack Klein

Yes, C has objects. (They have nothing to do with what's commonly
called "object-oriented programming".)

....and interestingly enough, if slightly OT, is the fact that the
definition of the term 'object' in C++ is the same as it is in C.
 
J

Jack Klein

junky_fellow wrote on 07/08/04 :

A variable.

const int x = 10;

'x' is an object.

char *hello_world = "hello world";

Both the pointer and the string literal it points to are objects.
 
E

E. Robert Tisdale

junky_fellow said:
What is a C object?

A *data* object.
If I have some function "func()" in my C program,
then can I say that "func()" is a C object?
Yes.

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?
Yes.

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

Yes. Objects are *data* objects
in the context of any computer programming language.

Be aware that the term *object* also has a special meaning
in the context of ISO C standards documents
which corresponds roughly to mutable storage, lvalues or variables.
 
E

E. Robert Tisdale

pete said:
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.
 
K

Keith Thompson

An object is a region of data storage in the execution
environment (3.14).

A variable is an identifier for an object introduced by a
declaration.

An object does not need to have a variable.

The C standard does not define the term "variable". It uses it
informally, but only a few times.

There was a long and futile discussion here recently about whether
something like *ptr is a variable (there is no definitive answer).

<OT>The C++ standard does define the term "variable"; I don't remember
what the definition is.</OT>
 
S

Stefan Ram

Keith Thompson said:
The C standard does not define the term "variable". It uses it
informally, but only a few times.

Yes.
(An approximate meaning might be derived from those uses.)
There was a long and futile discussion here recently about whether
something like *ptr is a variable (there is no definitive answer).

I would not call it a variable. Obviously, it is an expression.
<OT>The C++ standard does define the term "variable"; I don't remember
what the definition is.</OT>

C++: "A variable is introduced by the declaration of an
object."

In Java the word "variable" is used more in the sense of the
"object" of C; so the term does not have a meaning independent
of a programming language.

However, in ISO 2382-2 a variable is "An entity whose value
may be indeterminate, or indeterminate between known limits,
until an actual value is assigned to it in a given
application."

The ISO 2382-15 is more relevant regarding programming
languages and it says: "A quadruple, established by a
declaration or an implicit declaration, that consists of an
identifier, a set of data attributes, one or more addresses,
and data values, where the relationship between the addresses
and the data values may vary."

See also:

http://www.ncits.org/tc_home/k5htm/v.htm#variable
 
S

Stefan Ram

However, in ISO 2382-2 a variable is "An entity whose value ...
The ISO 2382-15 is more relevant regarding programming
languages and it says: "A quadruple, established by a ...

And ISO/IEC 9899:1999 (E) even happens to refer to ISO 2382,
but unfortunately only to ISO 2382-1, not to ISO 2382-2 or
-15. Otherwise that would give us a definition of "variable"
for ISO/IEC 9899:1999 (E).
 
M

Mike Wahler

Mabden said:
C has objects? When did that happen?!

Boy I have GOT to get one of these new "standards" gizmos...

C has always had objects. An example:

int i; /* an object of type 'int' */

-Mike
 
M

Mike Wahler

E. Robert Tisdale said:
No.

malloc() doesn't create objects.
Correct.

It returns a pointer of type void*.

... at which address an object or objects may be stored.
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 i; /* is 'i' an object? The language standard says it is */
return 0;
}

-Mike
 
E

Emmanuel Delahaye

E. Robert Tisdale wrote on 07/08/04 :
A *data* object.


No.


No.


Yes. Objects are *data* objects
in the context of any computer programming language.

So how a function could be an object ? There is a flaw in your logic.
BTW, the forum topic is unambigous. It's the C-language, opposite to
'any computer programming language'
Be aware that the term *object* also has a special meaning
in the context of ISO C standards documents
which corresponds roughly to mutable storage, lvalues or variables.

Yes, this is why a function is not an object.
 
S

Stefan Ram

RCollins said:
Yes, it identifies an object of the type integer.

The number of objects being bound to i depends on the
execution.

Here is one 'i' (in the source code) being bound to up to 3
objects during execution and another one being bound to no
object at all.

#include <stdio.h> /* printf */

int main( void ) { int i; static char count = 0;
if( count++ < 3 )main();
else printf( "Now we got 3 int objects!" ); }

static int main0( void )
{ int i; /* this "i" never is never bound to any object */ }

In the declaration "static int i;" the "i" is better suited to
be identified with an object (for each instance of program
execution).
 
R

RCollins

Stefan said:
The number of objects being bound to i depends on the
execution.

Here is one 'i' (in the source code) being bound to up to 3
objects during execution and another one being bound to no
object at all.

#include <stdio.h> /* printf */

int main( void ) { int i; static char count = 0;
if( count++ < 3 )main();
else printf( "Now we got 3 int objects!" ); }

Since you are calling main() recursively, aren't you actually
creating 3 different i's? Each i is _not_ the same, even though
they happen to have the same name.
static int main0( void )
{ int i; /* this "i" never is never bound to any object */ }

In the declaration "static int i;" the "i" is better suited to
be identified with an object (for each instance of program
execution).

"Bound"? I don't know what that means in C (although I understand
the concept from ProLog). In this case, your example seems very
compiler-specific (or perhaps, optimization-specific). The compiler
is perfectly free to allocate memory storage to i, even if it is
never used to store a value. That would make i an object, regardless
of what (if anything) is stored in it. BTW, I don't see a "static int i"
anywhere ... you declared main() as static, but not the varible i.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,058
Members
48,769
Latest member
Clifft

Latest Threads

Top