Re: Adding the ability to add functions into structures?



On 30 Dec 2005 17:12:33 -0800, "Albert"
<albert.xtheunknown0@xxxxxxxxx> wrote in comp.lang.c:

> So structures are useful to group variables, so you can to refer to a
> collection as a single entity. Wouldn't it be useful to also have the
> ability to collect variable and functions?
>
> Ask K&R say, C programs consist of variables to store the input and
> functions to manipulate them.
>
> This would make C object-oriented - how cool would that be?
>
> Are there any problems with adding the ability to have functions
> encapsulated in structures?

It's already been done. They discuss it in comp.lang.c++, down the
hall. And in comp.lang.java, and I'm sure also in whatever group it
is on Microsoft's server that is devoted to C#.

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.

--
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

  • Adding the ability to add functions into structures?
    ... So structures are useful to group variables, so you can to refer to a ... collection as a single entity. ... Are there any problems with adding the ability to have functions ...
    (comp.lang.c)
  • Re: Adding the ability to add functions into structures?
    ... >So structures are useful to group variables, so you can to refer to a ... >Are there any problems with adding the ability to have functions ... require mechanisms by which data become executable. ... architectures cannot do that. ...
    (comp.lang.c)
  • Re: Adding the ability to add functions into structures?
    ... >> So structures are useful to group variables, so you can to refer to a ... >> collection as a single entity. ... > oriented programs in C right now. ... percent of object orientation is merely what good programmers were doing ...
    (comp.lang.c)