🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #2006

Re: C and its peasant 'ancestors'

#2006
From: David Brown
Date: Mon, 30 Nov 2026 08:44
66 lines
3309 bytes
On 29/11/2026 20:08, Bonita Montero wrote:
> Am 29.11.2026 um 17:19 schrieb Scott Lurndal:
> 
>> Commercial operating systems have used "virtual functions" in C pretty
>> extensively over the last forty years (consider the Unix VFS layer
>> or generic device driver interfaces for example).
> 
> Virtual functions in C++ need less storage since you need only one
> virtual method table pointer per baseclass. C-code is typically with
> one fuction pointer as a struct member. And C++ virtual functions are
> easier to handle since they're automatically set by the constructor.
> 
> 

True.

But they are also more indirect than function pointers contained 
directly in a struct (the common C method).  This can sometimes be 
significant, so there are pros and cons to both solutions.  The virtual 
method table is usually the better tradeoff, which is why it is used by 
C++, but it is not always so.

And of course you can do the same in C, albeit with more manual coding.

// C++
struct Foo {
	int x;
	int y;
	virtual void do_this();
	virtual int do_that(int z);
};

Foo foo;
foo.do_this();


// C with "traditional" C virtual functions:

struct Foo {
	int x;
	int y;
	void (*do_this)(void);
	int (*do_that)(int z);
};

struct Foo foo;
foo.do_this();


// C with virtual method table :

struct Foo_methods {
	void (*do_this)(void);
	int (*do_that)(int z);
};

struct Foo {
	struct Foo_methods * p_vmt;
	int x;
	int y;
};

struct Foo foo;
foo.p_vmt->do_this();

Technical Details
Message-ID: <11ejd19$8ku6$1@dont-email.me>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <11dup6q$v4j9$1@dont-email.me> <11e8ti0$hhqa$1@dont-email.me> <11e8v24$i2mc$2@raubtier-asyl.eternal-september.org> <11e9045$ihk3$1@dont-email.me> <11e90a8$ikh0$1@dont-email.me> <11e90mv$io87$2@raubtier-asyl.eternal-september.org> <11e91ns$j5dv$1@dont-email.me> <11e92ff$jclo$1@raubtier-asyl.eternal-september.org> <11e95j2$kimu$1@dont-email.me> <11e96aa$kpta$1@raubtier-asyl.eternal-september.org> <11ect54$20qpr$3@dont-email.me> <klFOS.164599$ZAo7.102690@fx18.iad> <11efabi$2rvk1$2@dont-email.me> <AgYOS.103415$mfg4.16519@fx36.iad> <11eht6p$3p4pj$1@raubtier-asyl.eternal-september.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: David Brown <david.brown@hesbynett.no>
Newsgroups: comp.lang.c
Subject: Re: C and its peasant 'ancestors'
Date: Mon, 30 Nov 2026 09:44:25 +0100
Organization: A noiseless patient Spider
Lines: 66
Message-ID: <11ejd19$8ku6$1@dont-email.me>
References: <11dup6q$v4j9$1@dont-email.me> <11e8ti0$hhqa$1@dont-email.me>
 <11e8v24$i2mc$2@raubtier-asyl.eternal-september.org>
 <11e9045$ihk3$1@dont-email.me> <11e90a8$ikh0$1@dont-email.me>
 <11e90mv$io87$2@raubtier-asyl.eternal-september.org>
 <11e91ns$j5dv$1@dont-email.me>
 <11e92ff$jclo$1@raubtier-asyl.eternal-september.org>
 <11e95j2$kimu$1@dont-email.me>
 <11e96aa$kpta$1@raubtier-asyl.eternal-september.org>
 <11ect54$20qpr$3@dont-email.me> <klFOS.164599$ZAo7.102690@fx18.iad>
 <11efabi$2rvk1$2@dont-email.me> <AgYOS.103415$mfg4.16519@fx36.iad>
 <11eht6p$3p4pj$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 30 Nov 2026 08:44:26 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="283590"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/RsTIhgDxZsgiQWgQagXBUn7KXODJCo6s="; posting-host="a448ec79be8238d2c3ca54b79fa3e2af"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:lDiY6XV4+dVWca1/umEhxnyb5xU= sha256:Dfx9I5qwSnhKThRVTgYDuxYA8i7rXQ900gsPIDbvrH0=
	sha1:eGlS7Ul4yTr5lteGoVeHTSkEl5g= sha256:64KJbbJgV1vFBF69D1BHdYk08beuEJ38ESw1yd88aMU=
Content-Language: en-GB, nb-NO
In-Reply-To: <11eht6p$3p4pj$1@raubtier-asyl.eternal-september.org>