Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | James Kuyper <jameskuyper@verizon.net> |
| Newsgroups | comp.std.c |
| Subject | Re: Conversion from void* to pointer-to-function? |
| Date | Mon, 25 Jun 2012 17:23:48 -0400 |
| Organization | A noiseless patient Spider |
| Lines | 35 |
| Message-ID | <4FE8D6E4.1060608@verizon.net> (permalink) |
| References | <ln62af6sum.fsf@nuthaus.mib.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | 7bit |
| Injection-Info | mx04.eternal-september.org; posting-host="2P71cupDoazVVolqpw1jrw"; logging-data="20523"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18EOFNeOaXz7zZxhhod9ghd1lyxnBL0ua4=" |
| User-Agent | Mozilla/5.0 (X11; Linux i686; rv:9.0) Gecko/20111220 Thunderbird/9.0 |
| In-Reply-To | <ln62af6sum.fsf@nuthaus.mib.org> |
| Cancel-Lock | sha1:/8w8ehMKE69jUSlmIikrPkj1gfY= |
| Xref | csiph.com comp.std.c:1383 |
Show key headers only | View raw
On 06/25/2012 04:26 PM, Keith Thompson wrote:
> Consider the following toy program:
>
> int main(void) {
> void *void_ptr = 0;
> void (*func_ptr)(void) = (void(*)(void))void_ptr;
> return 0;
> }
>
> (Note that void_ptr is *not* a null pointer constant, it's merely a
> pointer object that happens to contain a null pointer.)
>
> Is the conversion of void_ptr to void(*)(void) (a pointer-to-function
> type) permitted?
>
> N1570 6.5.4 lists three constraints for the cast operator. This code
> doesn't violate any of them.
>
> N1570 6.3.2.3 describes the semantics of conversions involving pointers.
> It mentions conversions from void* to and from pointer-to-object types,
> conversions from one pointer-to-object type to another, and conversions
> from one pointer-to-function type to another. Conversions from void* to
> a pointer-to-function type simply aren't mentioned.
Conversion of null pointers to other pointer types is mentioned
(6.3.6.3p4). It applies only to null pointers being converted to pointer
types, but there are no other type-based restrictions on the
applicability of that section.
> My conclusion is that the conversion is permitted (it doesn't violate
> any constraint or syntax rule), but its behavior is undefined by
> omission.
The behavior is defined by 6.3.6.3p4: it produces a null pointer of type
void(*)(void).
Back to comp.std.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Conversion from void* to pointer-to-function? Keith Thompson <kst-u@mib.org> - 2012-06-25 13:26 -0700
Re: Conversion from void* to pointer-to-function? James Kuyper <jameskuyper@verizon.net> - 2012-06-25 17:23 -0400
Re: Conversion from void* to pointer-to-function? Keith Thompson <kst-u@mib.org> - 2012-06-25 14:57 -0700
Re: Conversion from void* to pointer-to-function? Maxim Fomin <maxim@maxim-fomin.ru> - 2012-06-27 10:03 -0700
Re: Conversion from void* to pointer-to-function? Keith Thompson <kst-u@mib.org> - 2012-06-27 11:33 -0700
Re: Conversion from void* to pointer-to-function? David R Tribble <david@tribble.com> - 2012-07-24 20:05 -0700
Re: Conversion from void* to pointer-to-function? Tim Rentsch <txr@alumni.caltech.edu> - 2012-12-21 00:32 -0800
Re: Conversion from void* to pointer-to-function? Tijl Coosemans <tijl@coosemans.org> - 2012-12-21 10:00 +0100
Re: Conversion from void* to pointer-to-function? Keith Thompson <kst-u@mib.org> - 2012-12-21 02:01 -0800
Re: Conversion from void* to pointer-to-function? Tim Rentsch <txr@alumni.caltech.edu> - 2012-12-21 08:12 -0800
Re: Conversion from void* to pointer-to-function? Keith Thompson <kst-u@mib.org> - 2012-12-21 17:58 -0800
Re: Conversion from void* to pointer-to-function? Tim Rentsch <txr@alumni.caltech.edu> - 2012-12-22 08:22 -0800
csiph-web