Use func(void) for functions with no parameters

Поиск
Список
Период
Сортировка
От Bertrand Drouvot
Тема Use func(void) for functions with no parameters
Дата
Msg-id aTBObQPg+ps5I7vl@ip-10-97-1-34.eu-west-3.compute.internal
обсуждение исходный текст
Ответы Re: Use func(void) for functions with no parameters
Список pgsql-hackers
Hi hackers,

In C standards till C17, func() means "unspecified parameters" while func(void)
means "no parameters". The former disables compile time type checking and was
marked obsolescent in C99 ([1]).

This patch replaces empty parameter lists with explicit void to enable proper
type checking and eliminate possible undefined behavior (see [1]) if the function
is called with parameters. This also prevents real bugs (API misuse for example).

Remarks:

- C23 ([2]) made func() and func(void) equivalent and would produce an error
if an argument is passed.

- The patch has been generated with the help of a coccinelle script [3]. It does
modify 8 functions and did not touch the few ones in .c "test" files (libpq_testclient.c
for example).

[1]: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf
[2]: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf
[3]: https://github.com/bdrouvot/coccinelle_on_pg/blob/main/misc/use_func_void.cocci

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

Вложения

В списке pgsql-hackers по дате отправления: