Re: Adding the ability to add functions into structures?



On Sat, 31 Dec 2005 12:23:31 +0000 (UTC), "Malcolm"
<regniztar@xxxxxxxxxxxxxx> wrote in comp.lang.c:

>
> "Jack Klein" <jackklein@xxxxxxxxxxx> wrote
> > I know I'll get flamed for this, but with the exception of inheritance
> ^^^^^^^^^^^^^^^^^^^^^^^^
> > this is really nothing but syntactical sugar. You can write object
> > oriented programs in C right now.
> >
> > A perfect example is the FILE data type, declared an <stdio.h>. It
> > has a creator, fopen(), a destructor, fclose(), and all sorts of
> > methods you can invoke on it via its pointer, such as fprintf(),
> > fscanf(), fread(), fwrite(), between its successful creation and its
> > destruction.
> >
> Inheritance is crucial.

Says who? The first hit on Google for the phrase "object oriented"
including quotations is
http://java.sun.com/docs/books/tutorial/java/concepts/, which has the
page title "Object-Oriented Programming Concepts". The first question
and answer on this page are:

What Is an Object?

An object is a software bundle of related variables and methods.
Software objects are often used to model real-world objects you find
in everyday life.

Further down the page comes the question "What is Inheritance".

Inheritance is a heavily-used feature that is provided by most object
oriented languages and systems, but it is indeed an extra feature. The
true definition of object orientation is pretty well captured in the
first question and answer. Object orientation means that data is
encapsulated and not manipulated directly, only via specifically
defined functions, often called "methods." And the C FILE type meets
this definition.

> An object is any set of data items that are "part of the same thing". C
> structures are therefore objects. (The C standard further specifies that an
> object must be stored contigously in memory. This is a language issue and a
> fairly obvious thing to do, but not strictly necessary).

That's quite correct. In actual fact, the definition of "object" in
the C++ language standard is exactly the same as it is in C, and has
nothing at all to do with classes or object oriented programming. In
C++, as in C, an int is an object.

> A program becomes "object-oriented" not when it uses objects, but when the
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This is an interesting point of view, and one perhaps subscribed to by
many programmers who use object oriented paradigms, perhaps in
languages that have more built-in support for it than C does. Still,
I would be mildly surprised if you could find an authoritative
definition of "object orientation" that states that inheritance is
required.

> objects enter into relationships with each other. In C++ like most lanauges
> that support obect-orientation, this is achieved via inheirtance. However
> there are other ways, for example Microsoft Windows objects all respond to
> the same message system, Java interfaces specify common methods, text
> adventure objects have verb handlers.

Actually, inheritance can be done in C as well, but the result tends
to be rather messy. Most people who attempt it are trying to write
C++ in C and, in my experience, the result is neither good C++ nor
good C.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
.



Relevant Pages

  • Re: Hows dot.net doing nowadays?
    ... You can achieve "Inheritance" in VB through two different mechanisms. ... C++), copy 'n paste, or through a new Interface, is irrelevant. ... on whatever language. ... because object orientation is a way of thinking more than anything else. ...
    (microsoft.public.vb.general.discussion)
  • Re: object orientated programming with linux
    ... > Well, no, because to be object oriented you have to have inheritance. ... very crippled form of object oriented programming without inheritance. ... "object orientation" exists without inheritance. ... Mark Nenadov ...
    (alt.linux)
  • Re: Container library progress
    ... But inheritance and classes are as essential to it as are methods. ... you're doing object oriented programming. ... that builds objects which contain data and the function pointers ...
    (comp.lang.c)
  • Re: Inheritance and Polymorhpism (getting back to the point)
    ... >>replaced with an inheritance hierarchy. ... > languages that, for the purpose of this discussion, we shall call ... base class will force a recompilation of all derived classes, ... in the tasks window, courtesy of static typing. ...
    (comp.object)
  • Re: Modula-2 vs. Oberon-2
    ... This is a bad substitute for real modules that most OO languages are ... the recursive call patterns produced by inheritance and object ... I believe that comes close to your idea of a "opaque type"? ...
    (comp.lang.modula2)