Standard type for code pointers?
Giorgos Keramidas
keramida at ceid.upatras.gr
Wed Apr 20 09:23:53 PDT 2005
On 2005-04-20 16:10, Joseph Koshy <joseph.koshy at gmail.com> wrote:
>> Except that intptr_t need only be large enough to hold an object
>> pointer. This is not necessarily enough to hold a function pointer.
>
> Right.
>
>> The only standard types that are guaranteed to be able to hold a
>> function pointer are other function pointers.
>
> Right, but there doesn't seem to be a C99 name for function
> pointer types.
There is no need for an explicit typedef. If you do know the type of
the function pointed at by a function pointer, you can declare the
pointer using the correct type:
char prog_name[] = "/bin/sh";
char *args[] = { prog_name };
int (*fptr)(int, char **);
fptr = main;
fptr(1, args);
> Is 'register_t' guaranteed to be wide enough?
AFAIK, no. Portable C code cannot assume that a function pointer is
small enough to fit in a single machine register. Some obscure
architecture may choose to represent function entry points with as
many register as it needs.
More information about the freebsd-standards
mailing list