Re: Adding the ability to add functions into structures?



Jack Klein wrote:

.... snip ...

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.

I see no reason for any fires. The only problem with your example is that you can't write (in general) that type in C. As a further example I suggest my hashlib, which is written in standard C, is also very much object oriented, offers constructors, destructors, and methods.


It offers the opaque incomplete object "hshtbl", whose details are completely hidden. This is unlike FILE*, which has to be incompletely hidden because of some standards constraints. Of course hashlib has the advantage of being designed some 30 plus years later than the FILE system.

See: <http://cbfalconer.home.att.net/download/hashlib.zip>

--
"If you want to post a followup via groups.google.com, don't use
 the broken "Reply" link at the bottom of the article.  Click on
 "show options" at the top of the article, then click on the
 "Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
.



Relevant Pages