4

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!

4

3 に答える 3

6

C99標準のドラフトから:

3.14 実行環境におけるデータストレージの
オブジェクト領域。その内容は値を表すことができます。

だから、あなたは基本的に正しいです。

ノート:

  • オブジェクトには次の名前を付けることができます。int object = 42;
  • オブジェクトは、より大きなオブジェクトの一部にすることができます。struct tm x; /* (x) and (x.tm_year) are objects */
  • オブジェクトは動的に割り当てることができます:int *arr = malloc(42); if (arr) /* arr[4] is an object */;
于 2012-05-14T08:41:13.703 に答える
2

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.

于 2012-05-14T08:41:41.137 に答える
2

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

于 2012-05-14T08:47:24.647 に答える