0

I read that a running C program can be referred to as an "instance". Is this really correct? The word instance is usually used for OOP. And C also has "objects" hasn't it, but it's not the same as in OOP. An "object" in C is just something in memory like a union with some value could be called an object can't it?

Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424
  • 3
    "Instance" was used before OOP and can easily be used in other contexts. For instance, one can talk of "an instance" of the execution of a program. "Object" has many meanings, but I'm not recalling one specific to C. – Hot Licks Jan 31 '13 at 01:06
  • 2
    @HotLicks, the C standard uses the word 'object' to refer to a "region of data storage in the execution environment, the contents of which can represent values." – Carl Norum Jan 31 '13 at 01:11
  • @HotLicks Thank you for the comment. I'm certain I've seen the word "object" used about C stuff that are in memory. – Niklas Rosencrantz Jan 31 '13 at 01:11
  • 1
    @Nick - memory is unnecessary. For example, local variables are objects, but might only ever live in registers. – Carl Norum Jan 31 '13 at 01:12
  • @CarlNorum Thank you, that was what I was looking to verify. – Niklas Rosencrantz Jan 31 '13 at 01:12
  • 1
    I don't know what you mean by `things`. Consider revising your title. – Mikhail Jan 31 '13 at 01:12
  • @CarlNorum Ah ok the registers yes. I'm not that experienced with registers yet and mostly used registers when programming assembly (so assembly programs also can have "objects"(?)). – Niklas Rosencrantz Jan 31 '13 at 01:13
  • 2
    registers are a form of memory. – Jim Balter Jan 31 '13 at 01:17
  • 1
    @JimBalter true, true. In C, though, an object is something for which you can take the value. In general terminology "object" refers to something to which you can obtain a (possibly modifiable) handle. Pure values like `5` are not objects, and functional programming often enshrines value semantics so special tricks are needed for object orientation. In that area, the line between values and objects may even blur. – Potatoswatter Jan 31 '13 at 01:46
  • 1
    @CarlNorum et al - Yeah, it's been decades since I went through any of the C spec stuff in detail. I am recalling that the term "data object" is used fairly generically in many discussions of programming languages to refer to an addressable and (relatively) concrete item containing a value (where the "address" may be a storage address or a register address or whatever). – Hot Licks Jan 31 '13 at 02:58
  • 1
    @Mikhail - I think "things" is a much better term to use here than "stuff". – Hot Licks Jan 31 '13 at 03:00
  • 1
    @Potatoswatter Your comment has nothing to do with what I wrote. registers aren't values, and `register` in C is just a hint that the compiler can ignore (in C++ you can even take the address of variables declared `register`). My point was that Carl's statement "memory is unnecessary" is wrong -- local variables require some sort of memory, and the implementation is free to choose what kind. – Jim Balter Jan 31 '13 at 20:22
  • Thanks for all the comments. I'm still not sure what I can't call an object besides perhaps pointers. Anything real could be called an object and even a pointer could be represented by an object or entity. – Niklas Rosencrantz Mar 16 '13 at 21:03

1 Answers1

4

An "object" in C is just something in memory, but that's also true of all computer languages.

An object in real life is a thing that physically exists. Being in memory is the closest something in a program can come to physical existence, so we apply the same term.

An instance in real life is a specific example of a generic concept. The term has similar generality in computers. When you tell the computer to run a program, it generates an instance of that program, among many potential instances of running that program. Again, nothing specific to C, this terminology usually occurs in operating systems (which manage running of programs, and define what a "program" is).

Potatoswatter
  • 134,909
  • 25
  • 265
  • 421