Re: Adding the ability to add functions into structures?



Jack Klein said:

> I know I'll get flamed for this,

FLAME ON!!!

> but with the exception of inheritance
> this is really nothing but syntactical sugar. You can write object
> oriented programs in C right now.

Oh. Was that it? Sheesh. Flame off again. (sigh)

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

This is pretty much how I do it, yes. Just a minor nit - FILE isn't (quite)
a perfect example, in at least two ways:

1) FILE should, in my opinion, be a truly opaque type, with the structure
definition hidden internally. typedef struct _iobuf FILE; is already more
than we need to know. The whole schmeer is far, far more than we need to
know.

2) I wish I wish I wish that fclose took FILE ** rather than FILE *, don't
you?

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
.