🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #976

Re: OOP in C...

#976
From: Chris M. Thomasson
Date: Wed, 28 Oct 2026 21:47
68 lines
2693 bytes
On 10/27/2026 10:21 PM, steve g wrote:
> "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:
> 
>> Fwiw, google groups seems to be working again! Found an older OOP thing I
>> made:
> 
> Oh good. For OOP gcc supports empty structures...?

Iirc, it sure does. But its non std.



>> https://pastebin.com/raw/f52a443b1
>> (no ads, no shit...)

It was an old attempt Steve. Take close note: I used macros for the 
"pseudo" duck typing, but they have a double eval. That can be cleaned 
up for sure:
______________
#define object_destroy(mp_self) ( \
   (mp_self)->vtable->object.fp_destroy((mp_self)) \
)


#define device_read(mp_self, mp_buf, mp_size) ( \
   (mp_self)->vtable->device.fp_read((mp_self), (mp_buf), (mp_size)) \
)


#define device_write(mp_self, mp_buf, mp_size) ( \
   (mp_self)->vtable->device.fp_write((mp_self), (mp_buf), (mp_size)) \
)
______________


using them:
_______________
/* Sample Application
____________________________________________________________________*/
void read_write(
  struct device* const self
) {
   char buf[100];

   device_read(self, buf, 50);

   device_write(self, buf, 5);
}


int main(void) {
   struct device* a_device;

   if (! usb_drive_create(&a_device)) {
     read_write(a_device);

     object_destroy(a_device);
   }

   return 0;
}
_______________


> thanx

No problem. Just one way to do it.
Technical Details
Message-ID: <11btqh3$2qqmv$1@dont-email.me>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <11blqhs$3vf3k$1@dont-email.me> <875wympfi7.fsf@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: OOP in C...
Date: Wed, 28 Oct 2026 14:47:13 -0700
Organization: A noiseless patient Spider
Lines: 68
Message-ID: <11btqh3$2qqmv$1@dont-email.me>
References: <11blqhs$3vf3k$1@dont-email.me> <875wympfi7.fsf@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 28 Oct 2026 21:47:16 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="2976479"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+mN7YiL4SQHRdOKTTsJhpWu2c9+7BR368="; posting-host="ce22479583babc8631500b8cafa91fe8"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:ivzto4l++sGIbj0mDmd0+f85/gY= sha256:C+mTNy3wuTcqr3+eQ3kEimZMBnv8letI38j0+wSLQs0=
	sha1:uQBZN+V2hI2cvtjJva3aSgEcAUo= sha256:xje1lgfXOxJM2SCvVsQoJjznJFvcg8JmoXVgW0vsL+4=
In-Reply-To: <875wympfi7.fsf@gmail.com>
Content-Language: en-US