The VikiD Truth

Knowledge base / Computing / C & systems languages

Objects in C

Here is the truth about “objects”: the word means different things in different traditions, and fights about OOP usually start from mixed definitions. In Smalltalk an object is a living entity that answers messages; in C++ it is a region of memory with a type; in JavaScript it is a mutable property bag with a prototype link.

What it is, in plain words

An object packages state (data) with behaviour (code that uses that data). Languages implement that idea differently:

Why it matters

Almost every mainstream UI toolkit, game engine and business app framework speaks in objects. Knowing which object model you’re in stops you from writing JavaScript as if it were Java – or Smalltalk as if it were C.

An everyday analogy: people at a desk

You don’t reach into someone’s skull and change their memories. You ask them to do something (“please print this”). They may refuse, delegate or act. That is the Smalltalk view. The C++ view is more like a labelled folder of papers with procedures stapled on. Both are called “objects”. Clarity demands saying which you mean.

A hands-on contrast

# Python – class-based
class Counter:
    def __init__(self): self.n = 0
    def inc(self): self.n += 1
c = Counter(); c.inc()
// JavaScript – prototype bag
const counter = {
  n: 0,
  inc() { this.n++; },
};
counter.inc();
"Smalltalk – message passing"
c := Counter new inc.
c count.
# PicoLisp – often symbols + properties / classes when needed
(class +Counter)
(dm inc> () (inc (:: n)))

Common misconceptions

Connections

Back to C Programming

In C, the term object refers to a location in memory whose contents can represent values.

Objects that have named identifiers are called variables.

Last edited · 4 revisions

Tags: #Computing