Re: style for typedef of function that will be pointed to - Mailing list pgsql-hackers

From Chapman Flack
Subject Re: style for typedef of function that will be pointed to
Date
Msg-id 620195FD.6060900@anastigmatix.net
Whole thread Raw
In response to Re: style for typedef of function that will be pointed to  (Chapman Flack <chap@anastigmatix.net>)
List pgsql-hackers
On 10/05/21 14:00, Chapman Flack wrote:
> On 10/05/21 13:47, Tom Lane wrote:
>>> An alternative I've sometimes used elsewhere is to typedef the function
>>> type itself, and use the * when declaring a pointer to it:
>>> typedef void Furbinator(char *furbee);
>>
>> Is that legal C?  I doubt that it was before C99 or so.  As noted
>> in the Ghostscript docs you came across, it certainly wouldn't have
>> been portable back in the day.
> 
> It compiles silently for me with gcc --std=c89 -Wpedantic
> 
> I think that's the oldest standard I can ask gcc about. Per the manpage,
> 'c89' is ISO C90 without its amendment 1, and without any gnuisms.

There are some places in the tree where AssertVariableIsOfType is being
cleverly used to achieve the same thing:

void
_PG_output_plugin_init(OutputPluginCallbacks *cb)
{
  AssertVariableIsOfType(&_PG_output_plugin_init, LogicalOutputPluginInit);


void
_PG_archive_module_init(ArchiveModuleCallbacks *cb)
{
  AssertVariableIsOfType(&_PG_archive_module_init, ArchiveModuleInit);


While clever, doesn't it seem like a strained way to avoid just saying:

typedef void ArchiveModuleInit(ArchiveModuleCallbacks *cb);


ArchiveModuleInit _PG_archive_module_init;

void
_PG_archive_module_init(ArchiveModuleCallbacks *cb)
{


if indeed compilers C90 and later are happy with the straight typedef?

Not that one would go changing existing declarations. But perhaps it
could be on the table for new ones?

Regards,
-Chap



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: [RFC] building postgres with meson - autogenerated headers
Next
From: Greg Stark
Date:
Subject: WaitLatchOrSocket seems to not count to 4 right...