473,698 Members | 2,398 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 4883


E. Robert Tisdale wrote:
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.
"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.

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.


I think, in this case, "unitialize d" might mean "unknown".
For example:

void foo(void) {
int i; /* uninitialized value here */

printf("i=%d\n" , i);
}

(ignoring the undefined behaviour for now) will print
out some unknown decimal value.

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.

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


Joe Wright wrote:
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.


What if *ui (since it is un-initialized) contains a trap representation?
Is it still considered an int object?

--
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 #32
RCollins wrote:


Joe Wright wrote:
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.

What if *ui (since it is un-initialized) contains a trap representation?
Is it still considered an int object?

Sure, why not?

--
Joe Wright mailto:jo****** **@comcast.net
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 14 '05 #33


Joe Wright wrote:
RCollins wrote:


Joe Wright wrote:
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.


What if *ui (since it is un-initialized) contains a trap representation?
Is it still considered an int object?

Sure, why not?


I just wanted to make sure I was on the 'same page' as the other
posters in this thread.

--
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 #34
Emmanuel Delahaye wrote:
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.


Thanks ed, you're right, of course. My point is that defining ui as
pointer to unsigned int, while creating the pointer, does not create
the unsigned int. Before the successful malloc() above, the contents
of ui is indeterminate and any reference to *ui or ui[0] causes
undefined behaviour. If, and only if, the malloc() succeeds does
ui[0] become an object.

--
Joe Wright mailto:jo****** **@comcast.net
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 14 '05 #35
RCollins wrote:

Joe Wright wrote:
RCollins wrote:


Joe Wright wrote:

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.

What if *ui (since it is un-initialized) contains a trap representation?
Is it still considered an int object?

Sure, why not?


I just wanted to make sure I was on the 'same page' as the other
posters in this thread.


For
int Integer;
Integer, refers to an object even though it is uninitialized
and may contain a trap representation.

Functions have addresses but they're not objects,
register specified variables don't have addresses, but they're objects.
Except for those two things,
having an address in a C program is equivalent to being an object.

--
pete
Nov 14 '05 #36
pete wrote:
.... ******* SNIP 90 odd lines of garbage quotes ******* ...
For
int Integer;
Integer, refers to an object even though it is uninitialized
and may contain a trap representation.

Functions have addresses but they're not objects,
register specified variables don't have addresses, but they're objects.
Except for those two things,
having an address in a C program is equivalent to being an object.


Please snip stuff not germane to your answer.

--
"Churchill and Bush can both be considered wartime leaders, just
as Secretariat and Mr Ed were both horses." - James Rhodes.
"A man who is right every time is not likely to do very much."
- Francis Crick, co-discover of DNA
Nov 14 '05 #37
pete wrote:
RCollins wrote:

Joe Wright wrote: .... I just wanted to make sure I was on the 'same page' as the other
posters in this thread.


For
int Integer;
Integer, refers to an object even though it is uninitialized
and may contain a trap representation.

Functions have addresses but they're not objects,
register specified variables don't have addresses, but they're objects.
Except for those two things,
having an address in a C program is equivalent to being an object.

So, it's kinda like a function isn't considered an object, by definition?

If I defined a structure with some data members and some pointers to
functions, could I then come up with some rationale for calling that an
"object?" Or is that too much of a stretch?

Thanks,
Rich

Nov 14 '05 #38
Rich Grise wrote on 11/08/04 :
So, it's kinda like a function isn't considered an object, by definition?
Yes. A function is not an object. It's a function!
If I defined a structure with some data members and some pointers to
functions, could I then come up with some rationale for calling that an
"object?" Or is that too much of a stretch?


A data member is an object
A pointer to a function is an object. The pointee is not an object.
A structure is an object

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

"C is a sharp tool"

Nov 14 '05 #39
Rich Grise wrote:

pete wrote:
RCollins wrote:

Joe Wright wrote: ... I just wanted to make sure I was on the 'same page' as the other
posters in this thread.
For
int Integer;
Integer, refers to an object even though it is uninitialized
and may contain a trap representation.

Functions have addresses but they're not objects,
register specified variables don't have addresses, but they're objects.
Except for those two things,
having an address in a C program is equivalent to being an object.

So, it's kinda like a function isn't considered an object,
by definition?


Yes.
There are three major catagories of types.
Function types
object types
incomplete types

Function types are defined by their parameter types
and their return types.
Object types like (char), are the types which have determinable sizes.
Incomplete types like (void) or (extern array[]) don't have sizes.
If I defined a structure with some data members and some pointers to
functions,
could I then come up with some rationale for calling that an
"object?" Or is that too much of a stretch?


There's nothing special about a structure being an object.

--
pete
Nov 14 '05 #40

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

Similar topics

2
8245
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
1883
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 than references for the STL library? I'd also prefer to avoid using const_cast, if it is indeed...
6
2570
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, I want to store classes of my objects in a vector. I also have three further questions:
3
3027
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 power and character of the language. Essentially, an object in JavaScript can be considered to...
8
1857
by: Lüpher Cypher | last post by:
Hi, Suppose we have a hierarchical class structure that looks something like this: Object | +-- Main | +-- Object1
161
7827
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
8218
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
2207
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
2556
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 as regions of storage in the memory.
14
6013
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
8678
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9166
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9030
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8899
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7737
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6525
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4621
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.