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

Re: Return type of dlsym

To: "Seeds, Glen" <yyyyyyyyyy@xxxxxxxxxx>
Subject: Re: Return type of dlsym
From: "Clive D.W. Feather" <yyyyy@xxxxxxxxx>
Date: Tue, 16 Apr 2002 16:50:45 +0100
Cc: yyyyyyyyyyyyyy@xxxxxxxxxxxxx
References: <FB15E670DA55D51185350008C786514A04579576@sottexch1.cognos.com>
> Wojtek Lerch said:
>> The funny thing is that I don't think the result of converting between a
>> data pointer and a function pointer by va_arg() is defined anywhere --
>> it seems to me that the text specifically says that the behaviour is not
>> undefined, but fails to define the behaviour...

I wrote:
> Then it's undefined behaviour. Failing to define behaviour is the same as
> saying "it's undefined".

Seeds, Glen said:
> I'm a little uncomfortable with the last statement.

Sorry, but that's stated *explicitly* in C90 and C99.

However, in this instance I think I misspoke.

Wojtek is, I presume, talking about code like this:

    typedef void (*vif_ptr)(int);

    void f (int n, ...)
    {
        va_list ap;
        vif_ptr fptr;

        va_start (ap, n);
        fptr = va_arg (ap, vif_ptr);
        va_end (ap);
        (*fptr)(n);
    }

    // ...

    int x;
    f (42, &x);

That is, the argument type is an object pointer but va_arg fetches a
function pointer (or vice versa).

If so, then this is *explicitly* undefined behaviour (7.15.1.1#2).

-- 
Clive D.W. Feather  | Work:  <yyyyy@xxxxxxxxx>   | Tel:  +44 20 8371 1138
Internet Expert     | Home:  <yyyyy@xxxxxxxxxx>  | Fax:  +44 870 051 9937
Demon Internet      | WWW: http://www.davros.org | Mobile: +44 7973 377646
Thus plc            |                            | NOTE: fax number change

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