Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Mon, 03 Sep 2012 21:51:54 -0500 Message-ID: <50456CC9.2150@mindspring.com> Date: Mon, 03 Sep 2012 22:51:53 -0400 From: pete Reply-To: pfiland@mindspring.com Organization: PF X-Mailer: Mozilla 3.04Gold (WinNT; I) MIME-Version: 1.0 Newsgroups: comp.lang.c Subject: Re: Do not cast pointers to functions to pointers to primitive types References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 56 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 4.156.228.154 X-Trace: sv3-3OYrTVvjHQJ1sL2ZIKnDqGuNW0kPtNSfR/zwWMBPZbf3pADbjUnke9Vw5/kmgxOZtlBlpa0WAFy8MVq!TnSyu5xsJ/QsQgMS5l1Q5tqmfZPGSdlhSYzGrXNeKxcn8RHecPtIe/guqxH30Hw5vagPLrWDWS+C!+3kw7qK97GM= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2970 Xref: csiph.com comp.lang.c:25887 Keith Thompson wrote: > > James Kuyper writes: > > On 09/03/2012 04:21 PM, Keith Thompson wrote: > >> James Kuyper 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