Reputation: 4260
Wheneven I go through some tutorials/notes for C, I quite come across the term "objects". I was always wondering what does the object got to do with the procedural language. Going a bit deep I could understand that something occupying a piece of memory is termed as an "object" in c.
My question is whether my understanding is correct or is there something I am missing. Thanks!
Upvotes: 4
Views: 5849
Reputation: 24584
In the C standard at least, an "object" is roughly a piece of data occupying contiguous memory. So int, long, float, pointer variables are all objects, as well as arrays or structs or arrays of structs, or data in malloc'd chunks of memory.
Upvotes: 2
Reputation: 111316
There was this post a while back on comp.lang.c related to this by the famous Chris Torek which may help you.
Upvotes: 2
Reputation: 108986
From the draft of the C99 Standard:
3.14
object
region of data storage in the execution environment, the contents of which can represent values
So, you're basically right.
Notes:
int object = 42;
struct tm x; /* (x) and (x.tm_year) are objects */
int *arr = malloc(42); if (arr) /* arr[4] is an object */;
Upvotes: 6