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


Groups > comp.lang.c > #25887

Re: Do not cast pointers to functions to pointers to primitive types

Message-ID <50456CC9.2150@mindspring.com> (permalink)
Date 2012-09-03 22:51 -0400
From pete <pfiland@mindspring.com>
Organization PF
Newsgroups comp.lang.c
Subject Re: Do not cast pointers to functions to pointers to primitive types
References <fce4988c-58d7-4847-84fe-edb1ed3b722c@googlegroups.com> <k227u5$i0a$1@dont-email.me> <lnzk56vov4.fsf@nuthaus.mib.org> <k235j8$q9j$1@dont-email.me> <lnpq62vkuk.fsf@nuthaus.mib.org>

Show all headers | View raw


Keith Thompson wrote:
> 
> James Kuyper <jameskuyper@verizon.net> writes:
> > On 09/03/2012 04:21 PM, Keith Thompson wrote:
> >> James Kuyper <jameskuyper@verizon.net> writes:
> >> [...]
> >>> Example: the dlsym() function is specified by the X-open standard to
> >>> take a void* argument which can be either a pointer to an object or a
> >>> pointer to a function. The Rationale for that function notes;
> >>>
> >> [...]
> >>>> Note that compilers conforming to the ISO C standard are required to
> >>>> generate a warning if a conversion from a void * pointer to a
> >>>> function pointer is attempted.
> >> [...]
> >>
> >> I don't believe that's correct.  The behavior of converting a void*
> >> pointer to a function pointer is not defined, but as far as I can tell
> >> it doesn't violate any constraint.
> [...]
> >
> > It's possible that they're referring to implicit conversion, rather than
> > one using a cast.
> 
> It's possible, but if so they phrased it poorly.
> 
> Note that gcc also appears to get this wrong (assuming my interpretation
> is correct).  With "-std=c11 -pedantic", gcc 4.7 complains:
> 
>     warning: ISO C forbids conversion of object pointer to function pointer type [-pedantic]

This expression is defined, 
if it occurs where main is in scope: 

     ((void *)0 != main)

N1570

6.3.2.3 Pointers
3
If a null pointer constant 
is converted to a pointer type, 
the resulting pointer, called a null pointer, 
is guaranteed to compare unequal
to a pointer to any object or function.

6.5.9 Equality operators
Semantics
5
If one operand is a pointer 
and the other is a null pointer constant, 
the null pointer constant 
is converted to the type of the pointer.

-- 
pete

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


Thread

Do not cast pointers to functions to pointers to primitive types ajaybgr <ajay.bgr@gmail.com> - 2012-09-03 01:50 -0700
  Re: Do not cast pointers to functions to pointers to primitive types Ian Collins <ian-news@hotmail.com> - 2012-09-03 20:59 +1200
  Re: Do not cast pointers to functions to pointers to primitive types Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-09-03 02:13 -0700
  Re: Do not cast pointers to functions to pointers to primitive types Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-09-03 11:24 +0100
  Re: Do not cast pointers to functions to pointers to primitive types James Kuyper <jameskuyper@verizon.net> - 2012-09-03 08:31 -0400
    Re: Do not cast pointers to functions to pointers to primitive types Keith Thompson <kst-u@mib.org> - 2012-09-03 13:21 -0700
      Re: Do not cast pointers to functions to pointers to primitive types James Kuyper <jameskuyper@verizon.net> - 2012-09-03 16:57 -0400
        Re: Do not cast pointers to functions to pointers to primitive types Keith Thompson <kst-u@mib.org> - 2012-09-03 14:48 -0700
          Re: Do not cast pointers to functions to pointers to primitive types pacman@kosh.dhis.org (Alan Curry) - 2012-09-03 21:57 +0000
            Re: Do not cast pointers to functions to pointers to primitive types Keith Thompson <kst-u@mib.org> - 2012-09-03 18:11 -0700
              Re: Do not cast pointers to functions to pointers to primitive types pacman@kosh.dhis.org (Alan Curry) - 2012-09-04 02:03 +0000
                Re: Do not cast pointers to functions to pointers to primitive types Keith Thompson <kst-u@mib.org> - 2012-09-03 19:20 -0700
                Re: Do not cast pointers to functions to pointers to primitive types pacman@kosh.dhis.org (Alan Curry) - 2012-09-04 20:27 +0000
                Re: Do not cast pointers to functions to pointers to primitive types James Kuyper <jameskuyper@verizon.net> - 2012-09-04 17:10 -0400
                Re: Do not cast pointers to functions to pointers to primitive types Barry Schwarz <schwarzb@dqel.com> - 2012-09-04 14:14 -0700
          Re: Do not cast pointers to functions to pointers to primitive types pete <pfiland@mindspring.com> - 2012-09-03 22:51 -0400
      Re: Do not cast pointers to functions to pointers to primitive types Vincenzo Mercuri <vincenzo.mercuri@yahoo.it> - 2012-09-04 00:02 +0200
        Re: Do not cast pointers to functions to pointers to primitive types Keith Thompson <kst-u@mib.org> - 2012-09-03 18:19 -0700
  Re: Do not cast pointers to functions to pointers to primitive types Kaz Kylheku <kaz@kylheku.com> - 2012-09-04 01:18 +0000
    Re: Do not cast pointers to functions to pointers to primitive types "Scott Fluhrer" <sfluhrer@ix.netcom.com> - 2012-09-04 11:59 -0400
      Re: Do not cast pointers to functions to pointers to primitive types Philip Lantz <prl@canterey.us> - 2012-09-06 21:34 -0700

csiph-web