Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.std.c > #1783

Re: Conversion from void* to pointer-to-function?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail
From Keith Thompson <kst-u@mib.org>
Newsgroups comp.std.c
Subject Re: Conversion from void* to pointer-to-function?
Date Fri, 21 Dec 2012 02:01:08 -0800
Organization None to speak of
Lines 43
Message-ID <lntxrfpvvf.fsf@nuthaus.mib.org> (permalink)
References <ln62af6sum.fsf@nuthaus.mib.org> <kfnsj6z7qkv.fsf@x-alumni2.alumni.caltech.edu>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Injection-Info mx04.eternal-september.org; posting-host="5842a546a2d4559ed11e9ac4721da702"; logging-data="17082"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Nz3PBytdtW2H0xMqKBftO"
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)
Cancel-Lock sha1:MgvD0cXgPSc59R4d9xHJE3lRTjU= sha1:a7KGiDAdKJUsSRt3ubtaS8SWjJ0=
Xref csiph.com comp.std.c:1783

Show key headers only | View raw


Tim Rentsch <txr@alumni.caltech.edu> writes:

> Keith Thompson <kst-u@mib.org> writes:
>
>> Consider the following toy program:
>>
>> int main(void) {   
>>     void *void_ptr = 0;
>>     void (*func_ptr)(void) = (void(*)(void))void_ptr;
>>     return 0;
>> }
[...]
>> My conclusion is that the conversion is permitted (it doesn't violate
>> any constraint or syntax rule), but its behavior is undefined by
>> omission.
>
> I agree with this conclusion.
>
>> Note that the authors of gcc seem to have a different interpretation;
>> on the above code, gcc-4.7 with "-std=c99 -pedantic" produces the
>> following warning:
>>
>>     warning: ISO C forbids conversion of object pointer to function pointer type [-pedantic]
>
> I interpret gcc's message differently, especially since it is a
> warning.  Since there is at least potential confusion about
> whether the ISO standard allows such conversions, they feel
> obliged to give a diagnostic (but without preventing compilation)
> to be on the safe side for being a conforming implementation.
> When in doubt, issue a diagnostic - no harm for being wrong
> on that side of the fence.

gcc issues mere warnings for a lot of things that are constraint
violations.  The -pedantic option is intended to enable all the
diagnostics that the standard requires.  The -pedantic-errors
option makes those diagnostics fatal.  With -pedantic-errors,
the above warning becomes a fatal error.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

Back to comp.std.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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