26

I'm not talking about object in C++ nor Objective C. I am trying to understand what "object" means in the context of this text:

If the declaration of a file-scope identifier for an object or a function contains the storage-class-specifier static, the identifier has internal linkage. Otherwise, the identifier has external linkage. See Storage Classes for a discussion of the storage-class-specifier nonterminal.

Within one translation unit, each instance of an identifier with internal linkage denotes the same identifier or function. Internally linked identifiers are unique to a translation unit.

I have already seen the word "object" in other different C topics. But when I Google it, I only get references to C++.

I read it also here and here.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
user3646717
  • 1,095
  • 2
  • 12
  • 21
  • 1
    Note that the definition of object in the C++ standard has nothing to do with OOP either. "_An object is a region of storage_" (C++11 draft n3290 §1.8). – Mat Oct 27 '14 at 06:45
  • Probably best explained here: http://stackoverflow.com/questions/1564359/object-code-linking-time-in-c-language – Rob Oct 27 '14 at 12:20
  • @Rob: that has nothing to do with this question. – Mat Oct 28 '14 at 06:13

1 Answers1

29

The term object is defined by the C11 Standard section 3.15:

object

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

The text on your MSDN link is copy-pasted (without attribution!) from section 6.2.2/3 of the C11 Standard.

To interpret this definition, region of data storage is the key part. All variables are objects, and objects may also be allocated via malloc.

Community
  • 1
  • 1
M.M
  • 138,810
  • 21
  • 208
  • 365
  • 7
    As an aside you're probably better off reading directly from the standard or a standard draft, instead of googling terms. [See here](http://stackoverflow.com/questions/81656/where-do-i-find-the-current-c-or-c-standard-documents) for links. – M.M Oct 27 '14 at 04:28
  • I disagree with your interpretation though I'm speaking with hazy memory and without checking my own comment here. C code will be compiled into assembly code which will eventually work its way to object code and then to machine code. Do not take my steps for the object code verbatim but I do not believe variables are objects not allocated by malloc. EDIT: http://stackoverflow.com/questions/1564359/object-code-linking-time-in-c-language – Rob Oct 27 '14 at 12:16
  • So in simple english an object could be anything: variables, functions, structures? – user3646717 Oct 27 '14 at 17:56
  • 1
    @user3646717 Functions and structure definitions are not objects; they don't use any data storage. – M.M Oct 27 '14 at 18:30
  • 2
    @Rob your link is talking about "object code" or "object files" (this is a completely different meaning of the word "object" than the usage in this question) – M.M Oct 27 '14 at 18:32
  • If variables are objects, then why don't we just call them variables?. Sorry but I don't understand. – user3646717 Oct 27 '14 at 23:11
  • 1
    @user3646717 we do call variables variables. What you just said is like saying "if cats are animals why don't we just call them cats?" – M.M Oct 28 '14 at 02:57
  • also, "variables" isn't a Standard C term; and it doesn't make much sense to call a const object a "variable" – M.M Oct 28 '14 at 02:59
  • So, stupid question: if I have something like `struct { int foo; } bar[10];`, then do `bar`, `bar[3]`, and `bar[3].foo` *all* designate "objects", because they all have data storage? Or only `bar` itself, as the top-level storage entity? – ruakh Nov 14 '16 at 21:31
  • 1
    @ruakh they're all objects. Sometimes we say "subobject". – M.M Nov 14 '16 at 21:46