Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objects in C language

Tags:

c

object

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!

like image 667
Shash Avatar asked Dec 27 '22 00:12

Shash


2 Answers

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:

  • an object can have a name: int object = 42;
  • an object can be a part of a larger object: struct tm x; /* (x) and (x.tm_year) are objects */
  • an object can be allocated dinamycally: int *arr = malloc(42); if (arr) /* arr[4] is an object */;
like image 65
pmg Avatar answered Dec 31 '22 13:12

pmg


There was this post a while back on comp.lang.c related to this by the famous Chris Torek which may help you.

like image 42
dirkgently Avatar answered Dec 31 '22 13:12

dirkgently