473,698 Members | 2,598 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 4884
pete wrote:
Rich Grise wrote:

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.


This sentence here puts it very concisely. Thanks for this. :-)
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.

Ok, fair enough. What I should do though, is 'splain a little.
I learned to copy-n-paste C many moons ago, by the seat of my
pants with K&R at my elbow. I've been away from programming for
a few years, and now, looking into writing some stuff, I'm almost
overwhelmed with these newfangled languages that seem to have as
a foundation The Language Whose Name Shall Not Be Mentioned++.

Luckily, the main one I'm jumping in at is Qt, which has nice GUI
wrappers.

And so, with my foundation in C, such as it is, I'm trying to wrap my
mind around the philosophy of "Objects" as in The Other Language, or any
of those other OOps things. (is that an ironic acronym, or what? ;-) )

Thanks!
Rich

Nov 14 '05 #41
pete wrote:
Rich Grise wrote:

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.

I think I'm trying to prove that good ol' C can do anything those
fancy-schmancy OOps things can do - just define your data right.

But I think to do this, you'd have to be a programmer who has
Slack. Not necessarily that particular distro, more the attitude.

Events? Heck, we've got signals, haven't we?

Cheers!
Rich

Nov 14 '05 #42
pete wrote:

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


Sigh.

A 'struct' is not an object.
it introduces a User Defined Type (UDT).
An *object* is an *instance* of some *type*.
For example:

struct X {
int* p;
};

defines a *type* and *not* an object.

// pseudo constructor
struct X X_create(size_t n) {
struct X x; // a reference to the return value
x.p = (X*)malloc(n*si zeof(struct X);
// initialize the return value
return x;
}

int main(int argc, char* argv[]) {
size_t n = 16;
struct X x = X_create(n);
// x is an object of type struct X
// . . .
return 0;
}

The type defines
*all* of the values that an object of that type may have
so an object *must* be initialized to one of those values
if it is to be called an object of that type.
Nov 14 '05 #43
"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > writes:
pete wrote:
There's nothing special about a structure being an object.
Sigh.

A 'struct' is not an object.


First, he wrote "structure" , not "struct". I assume that by
"structure" he meant "an object of a struct type".

For example, given:
struct foo { int whatever; } obj;
it's reasonable to say that "obj" is the name of a structure (which
is, of course, an object). Just as, given
int i;
char c;
it's reasonably to say that "i" is the name of an integer and "c" is
the name of a character.

We can talk about a "struct type" vs. a "struct object", or an
"integer type" vs. an "integer object", if it's not clear from
context. In this case, I think it was.
it introduces a User Defined Type (UDT).
Why the gratuitous abbreviation (WTGA)?
An *object* is an *instance* of some *type*.
Agreed.
For example:

struct X {
int* p;
};

defines a *type* and *not* an object.
Of course.
// pseudo constructor
struct X X_create(size_t n) {
struct X x; // a reference to the return value
x.p = (X*)malloc(n*si zeof(struct X);
// initialize the return value
return x;
}

int main(int argc, char* argv[]) {
size_t n = 16;
struct X x = X_create(n);
// x is an object of type struct X
// . . .
return 0;
}
How is your "pseudo constructor" relevant to the point? Presenting an
example in pseudo-C++ is not helpful.

It would have been polite to try compiling the above code before you
posted it. In your X_create, function, x.p is a pointer to int, but
you assign to it a pointer to X. Presumably "X" should be "struct X";
you can leave out the "struct" keyword in C++, but not in C. You have
mismatched parentheses in the assignment statement.

And of course you cast the result of malloc(), but we've been over
that before.

If you meant the "n" argument to X_create to specify the number of
"struct X"s it would return, your entire interface is broken, since
X_create returns a single "struct X" value. If you meant to have x.p
point to an array of n ints, you're a little closer, but not much.

But even a correct version of your "X_create" function would be beside
the point, so I won't bother to fix it.
The type defines
*all* of the values that an object of that type may have
so an object *must* be initialized to one of those values
if it is to be called an object of that type.


Perhaps, but it doesn't have to be initialized to be called an object.
An object is a "region of data storage in the execution environment,
the contents of which can represent values" (C99 3.14).

And, of course, the term "object" as used in C has nothing at all to
do with object-oriented programming.

--
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 #44
Keith Thompson wrote:

"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > writes:
pete wrote:
There's nothing special about a structure being an object.


Sigh.

A 'struct' is not an object.


First, he wrote "structure" , not "struct". I assume that by
"structure" he meant "an object of a struct type".


Thank you.
An *object* is an *instance* of some *type*.


Agreed.


I would say that an instance of some type is an object,
but the objects that malloc returns pointers to,
don't have types until they are accessed by an identifier.

N869
3.15
[#1] object
region of data storage in the execution environment, the
contents of which can represent values
[#2] NOTE When referenced, an object may be interpreted as
having a particular type;

Tisdale has some agenda against using the standard's definition
of technical terms. He likes to define technical terms in C
according to his intuition, his American Collegiate Pocket Dictionary
and his recollections of whatever he felt was true about C
the last time that he compiled code.

--
pete
Nov 14 '05 #45
pete wrote:
.... snip ...
Tisdale has some agenda against using the standard's definition
of technical terms. He likes to define technical terms in C
according to his intuition, his American Collegiate Pocket
Dictionary and his recollections of whatever he felt was true
about C the last time that he compiled code.


Well, with his return from some sort of hiatus he seems to have
curbed his worst attributes, and should be encouraged somewhat.
If he keeps it up criticism should be limited to technical errors.

--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
Nov 14 '05 #46
Rich Grise wrote:

pete wrote:
Rich Grise wrote:

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.

I think I'm trying to prove that good ol' C can do anything those
fancy-schmancy OOps things can do - just define your data right.


The definition wouldn't be an object, though.
The definition would only define the type.
When you declare a variable of that type,
then that identifier would refer to an object.

Object types also apply to constant expressions, which aren't objects.
int (0)
unsigned (0u)
double (0.0)
float (0.0f)

--
pete
Nov 14 '05 #47
Keith Thompson wrote:
E. Robert Tisdale writes:
The type defines
*all* of the values that an object of that type may have
so an object *must* be initialized to one of those values
if it is to be called an object of that type.


Perhaps, but it doesn't have to be initialized to be called an object.
An object is a "region of data storage in the execution environment,
the contents of which can represent values" (C99 3.14).

And, of course, the term "object" as used in C has nothing at all to
do with object-oriented programming.


Nov 14 '05 #48
Keith Thompson wrote:
E. Robert Tisdale writes:
The type defines
*all* of the values that an object of that type may have
so an object *must* be initialized to one of those values
if it is to be called an object of that type.

Perhaps, but it doesn't have to be initialized to be called an object.
An object is a "region of data storage in the execution environment,
the contents of which can represent values" (C99 3.14).

And, of course, the term "object" as used in C
has nothing at all to do with object-oriented programming.


'When I use a word,'
Humpty Dumpty said, in a rather scornful tone,
'it means just what I choose it to mean, neither more nor less.'

http://sundials.org/about/humpty.htm

What do you think the term 'object" means
in the phrase 'object-oriented programming'?
Are you saying that it is not possible
to write object-oriented programs in C?

Why not say 'region of data storage' instead of object
if that is all that is meant by object?

What I am saying is that the English language is badly abused
in the standards documents.
It converts ordinary English words into meaningless jargon.
These redefinitions narrow the meaning of these words
to the point where it is impossible to make valid inferences
and require the redefinition of other common terms.
For example, your redefinition of object appears to require
the redefinition of the term type
to include *all* of the values that could be represented
by the "region of storage" that you call a type.
This, in turn, seems to imply that the type depends
upon the representation that the programmer chooses
and that data abstraction is impossible in C.

Take for example

struct X {
int* p;
};

struct X x;

Does the object referenced through x include
the region of data pointer to by p?
Nov 14 '05 #49
"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > writes:
Keith Thompson wrote:
E. Robert Tisdale writes:
The type defines
*all* of the values that an object of that type may have
so an object *must* be initialized to one of those values
if it is to be called an object of that type.
Perhaps, but it doesn't have to be initialized to be called an object.
An object is a "region of data storage in the execution environment,
the contents of which can represent values" (C99 3.14).

And, of course, the term "object" as used in C
has nothing at all to do with object-oriented programming.

[Humpty Dumpty quotation deleted'
What do you think the term 'object" means
in the phrase 'object-oriented programming'?
I don't have a good answer to that. All I can say (and all I care to
say) is that the usual meaning of "object" in the context of
object-oriented programming is different from the definition in the C
standard (C99 3.14):

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

NOTE When referenced, an object may be interpreted as having a
particular type; see 6.3.2.1.

(The note is not part of the definition.)

The C90 definition is more verbose (C90 3.14), but it expresses the
same basic idea:

A region of data storage in the execution environment, the
contents of which can represent values. Except for
bit-fields, objects are composed of contiguous sequences of one or
more bytes, the number, order, and encoding of which are either
explicitly specified or implementation-defined. When referenced,
an object may be interpreted as having a particular type, see
6.2.2

(That may not be an exact quote; my copy of the C90 standard makes
cut-and-paste difficult.)
Are you saying that it is not possible
to write object-oriented programs in C?
No, I'm not saying that, nor have I ever said anything resembling it.
Why do you ask?
Why not say 'region of data storage' instead of object
if that is all that is meant by object?

What I am saying is that the English language is badly abused
in the standards documents.
It converts ordinary English words into meaningless jargon.
These redefinitions narrow the meaning of these words
to the point where it is impossible to make valid inferences
and require the redefinition of other common terms.
No, it converts ordinary English words into meaningful jargon. Any
field of discourse has its own jargon, consisting of ordinary words
with specific definitions, phrases, and, in some cases, invented
words. (The word "object" in everyday English has a meaning that's
not particularly useful in the context of programming languages, for
example.)

If you're going to discuss C, as you insist on doing, you have to
understand the way the C standard defines certain terms. If you're
going to use terms defined in the C standard in ways inconsistent with
their definitions, you're going to have difficulties communicating in
this newsgroup (as you've already discovered).
For example, your redefinition of object appears to require
the redefinition of the term type
to include *all* of the values that could be represented
by the "region of storage" that you call a type.
It's not *my* redefinition, it's in the C standard. Apart from that,
I'm not sure what you mean.
This, in turn, seems to imply that the type depends
upon the representation that the programmer chooses
and that data abstraction is impossible in C.
Nonsense.
Take for example

struct X {
int* p;
};

struct X x;

Does the object referenced through x include
the region of data pointer to by p?


Given the C standard's definition of "object", the object named x
includes the storage for x.p, but it doesn't include the region of
data pointed to by x.p. If you want to refer to both x and the data
pointed to by x.p as a single entity, you should choose a name other
than "object"; I suggest "data structure".

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

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
7828
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
8680
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
8609
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9169
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
5861
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2335
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.