Re: ISO C 23 on macOS
Paul Eggert <[email protected]>
| Newsgroups | gmane.comp.lib.gnulib.bugs |
|---|---|
| Organization | UCLA Computer Science Department |
| Message-ID | <[email protected]> |
On 2026-08-21 21:49, Bruno Haible via Gnulib discussion list wrote:
> Any workaround that comes to mind?
Aside from assembly language, the only thing I can think of is "typedef sometype (*generic_function_t) (sometypes);" and then casting the function pointer to its correct type before use. Something like the following, perhaps.
#include <stdio.h>
typedef int (*old_generic_function_t) ();
#if __STDC_VERSION__ >= 202300
/* A type suitable for holding a function pointer, after casting it to this type.
A value of this type should never be used to call a function.
Cast the value to the proper function type before calling.
The incomplete struct type helps prevent improper use. */
typedef struct _X_incomplete (*new_generic_function_t) (struct _X_incomplete);
#endif
int
f (int x)
{
return x + 42;
}
old_generic_function_t fp1 = (old_generic_function_t) f;
#if __STDC_VERSION__ >= 202300
new_generic_function_t fp2 = (new_generic_function_t) f;
# define fp2 ((int (*) (int)) fp2)
#endif
int (*fp3) (int) = f;
int
main ()
{
#if !(defined __cplusplus || __STDC_VERSION__ >= 202300) /* Avoid error "too
many arguments to function" */
printf ("Calling f through old_generic_function_t: %d\n", fp1 (100));
#endif
#if __STDC_VERSION__ >= 202300
printf ("Calling f through new_generic_function_t: %d\n", fp2 (1000));
#endif
printf ("Calling f through precise function type: %d\n", fp3 (10000));
}