Re: style for typedef of function that will be pointed to

Поиск
Список
Период
Сортировка
От Chapman Flack
Тема Re: style for typedef of function that will be pointed to
Дата
Msg-id 620195FD.6060900@anastigmatix.net
обсуждение исходный текст
Ответ на Re: style for typedef of function that will be pointed to  (Chapman Flack <chap@anastigmatix.net>)
Список 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 по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: [RFC] building postgres with meson - autogenerated headers
Следующее
От: Greg Stark
Дата:
Сообщение: WaitLatchOrSocket seems to not count to 4 right...