Re: Some pointer quiestions again



Mac wrote:
> On Tue, 31 May 2005 17:45:08 +0000, Jens.Toerring wrote:
>
> [snip]
>
> > [...] requiring that all pointer types
> > can be converted to and from a void pointer [...]
>
> Isn't this supposed to be all _object_ pointer types or something like
> that? What I am getting at is that ISTR that you cannot store a function
> pointer in a void pointer.

Correct. A function pointer can be converted to a void pointer [1] but
cannot portably be converted back again. A function pointer can be
converted to a function pointer of another type and back again though.

[1] I am not sure that a function pointer can even be converted to a
void pointer reliably, if not then there would appear to be no portable
way to print the value of a function pointer. If anyone can point to a
spot in the Standard that clarifies this, feel free.

Rob Gamble

.



Relevant Pages

  • Re: Passing execution to a memory address
    ... forbidden initialization of function pointer with void pointer ... int add1 ...
    (comp.lang.c)
  • Re: function * = void *
    ... It doesn't have to be the *correct* kind of function pointer: ... It's prototyped to return a void *. ... The ISO C standard does not require that pointers to functions can be ...
    (comp.lang.c)
  • Re: Some pointer quiestions again
    ... A function pointer can be converted to a void pointer but ... You can do the conversion with a cast: ... >void pointer reliably, if not then there would appear to be no portable ...
    (comp.lang.c)
  • Re: man malloc
    ... % foo.c:14: warning: ISO C forbids conversion of function pointer to object pointer type ...
    (freebsd-questions)
  • Re: function * = void *
    ... a.c:14: warning: ISO C forbids conversion of object pointer to function ... There is no guarantee that a function pointer can FIT in a void * ... It wouldn't surprise me if there will be new platforms where there ...
    (comp.lang.c)