[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: New warnings on emacs-26 branch with gcc 8.2.0

From: Bruno Haible
Subject: Re: New warnings on emacs-26 branch with gcc 8.2.0
Date: Sun, 19 Aug 2018 10:40:55 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-130-generic; KDE/5.18.0; x86_64; ; )

Yuri Khan wrote:
> > Indeed, casting through (void *) or (void (*) (void)) avoids the
> > warning.
> I seem to remember C does not guarantee that pointers to functions
> must survive casting through void*.

Yes, on some old architectures like Windows 3.1 a function pointer and
a 'void *' had different representations. But the fact that 'dlsym' has
a 'void *' return value proves that this is not an issue nowadays any more.

> It does for casting between
> function pointer types. So casting through (void (*)(void)) is going
> to be more portable.

No. GCC sometimes generates a __builtin_trap (a kind of undebuggable
abort()) when you cast function pointers in an incompatible way. (*) So,
I would avoid this.


(*) The precise conditions I know of are: 1. take the address of a declared
    function, 2. cast it to an incompatible function type, 3. invoke it
    with arguments according to this function type. But maybe there are
    other situations where the same thing occurs or might occur in the future?
    Who knows...

reply via email to

[Prev in Thread] Current Thread [Next in Thread]