Objects in C language

后端 未结 3 1557
名媛妹妹
名媛妹妹 2021-01-14 06:32

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 languag

相关标签:
3条回答
  • 2021-01-14 06:44

    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.

    0 讨论(0)
  • 2021-01-14 06:56

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

    0 讨论(0)
  • 2021-01-14 06:58

    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 */;
    0 讨论(0)
提交回复
热议问题