Email List: Xaustin-group-lX
[All Lists]

Re: [1003.1(2008)/Issue 7 0000074]: Pointer Types Problem

To: austin-group-l@xxxxxxxxxxxxx
Subject: Re: [1003.1(2008)/Issue 7 0000074]: Pointer Types Problem
From: Geoff Clare <gwc@xxxxxxxxxxxxx>
Date: Sat, 29 Aug 2009 10:22:34 +0100
References: <f6e89684e7d6fc9a7b734e179e7e9c6f@austingroupbugs.net> <20090827145851.GA24688@squonk.masqnet> <9FC357E76048C74C93F3BD3D69A16B8804B62ED0@nova.ott.qnx.com>
Wojtek Lerch <Wojtek@qnx.com> wrote, on 28 Aug 2009:
>
> > -----Original Message-----
> > From: Geoff Clare [mailto:gwc@opengroup.org] 
> > >   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 as in:
> > > 
> > >   fptr = (int (*)(int))dlsym(handle, "my_function");
> > 
> > I suggest adding:
> > 
> >     However, conversion using a cast like this is the only
> >     portable way of obtaining a function pointer from dlsym().
> 
> I also suggest removing the lie about the ISO C standard.  The above
> conversion has undefined behaviour in ISO C but it does not "require a
> warning".  ISO C does *allow* warnings (a.k.a. diagnostics) in this
> situation, and some compilers may take advantage of it, but that's just
> because ISO C allows compilers to generate diagnostics whenever they
> feel like it.

The dlsym() issue was discussed extensively in 2002, and the end
result was interpretation AI-003:

www.opengroup.org/austin/interps//uploads/40/1068/ai-003.txt

That's where the text about C99 requiring the warning is from.
The interpretation response also includes this statement about the
cast that used to be in the example (and is now being reinstated):

    "In this case, the 1999 C Standard does indeed require a warning
    to be issued for the function call shown in the dlsym() examples
    section on XSH P259, L8566."

I haven't re-read all of the 2002 discussion, but it seems to me
that if anyone had made a convincing argument that C99 does not
require the warning, then AI-003 would not have been approved with
that statement.  Interestingly, Don Cragun was initially of the
opinion that the warning was not required (austin-group-l 3761) but
later when he proposed the draft resolution for AI-003 he included
the statement that C99 does require the warning (austin-group-l 4123).
He produced the draft resolution as an action from the May 2002
meeting, so possibly it was discussions at that meeting that changed
his mind.  Unfortunately the minutes (Austin/106) just say:

    "XSH ERN 13: Many emails on this subject (dlsym! 109 messages in
    austin-group-l). ACTION 2002-05-06: DWC to propose response for
    XSH ERN 13 as an interpretation."

so the only way to know for sure would be if someone who attended
the meeting has some more detailed notes from it.

Personally, I can't find anything in C99 that requires the warning,
but just because I can't find it doesn't mean it's not there.

-- 
Geoff Clare <g.clare@opengroup.org>
The Open Group, Thames Tower, Station Road, Reading, RG1 1LX, England

<Prev in Thread] Current Thread [Next in Thread>