Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 20 Apr 2005 19:23:32 +0300
From:      Giorgos Keramidas <keramida@ceid.upatras.gr>
To:        Joseph Koshy <joseph.koshy@gmail.com>
Cc:        freebsd-standards@freebsd.org
Subject:   Re: Standard type for code pointers?
Message-ID:  <20050420162332.GB52948@orion.daedalusnetworks.priv>
In-Reply-To: <84dead720504200910441b9108@mail.gmail.com>
References:  <84dead720504200541539f4c15@mail.gmail.com> <03f22a3c76ac440b97e2179761dfd6fa@xcllnt.net> <20050420155407.GA844@falcon.midgard.homeip.net> <84dead720504200910441b9108@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2005-04-20 16:10, Joseph Koshy <joseph.koshy@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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050420162332.GB52948>