| From: | Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com> |
|---|---|
| To: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Subject: | Use func(void) for functions with no parameters |
| Date: | 2025-12-03 14:51:25 |
| Message-ID: | aTBObQPg+ps5I7vl@ip-10-97-1-34.eu-west-3.compute.internal |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | 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
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Use-func-void-for-functions-with-no-parameters.patch | text/x-diff | 5.5 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Matthias van de Meent | 2025-12-03 15:02:17 | Re: Use func(void) for functions with no parameters |
| Previous Message | Ashutosh Bapat | 2025-12-03 14:49:45 | Re: [PATCH] Add enable_copy_program GUC to control COPY PROGRAM |