Re: null function pointer?



pete <pfiland@xxxxxxxxxxxxxx> writes:

> Tim Rentsch wrote:
> >
> > pete <pfiland@xxxxxxxxxxxxxx> writes:
> >
> > > Chris Torek wrote:
> > > >
> > > > >> Keith Thompson <kst-u@xxxxxxx> writes:
> > > > >> > There is no conversion, explicit or implicit,
> > > > >> > defined between object pointers and function pointers
> > > >
> > > > >Tim Rentsch wrote:
> > > > >> Technically not quite correct. The code
> > > > >>
> > > > >> int (*pf)(void);
> > > > >>
> > > > >> pf = (void*)0;
> > > > >>
> > > > >> converts an object pointer value to a function pointer.
> > > > >> It's true, the object pointer expression in this
> > > > >> case is also a null pointer constant,
> > > > >> but the expression still yields a value of object pointer type,
> > > > >> and that value is converted by the assignment.
> > > >
> > > > In article <434CC4D1.5A1B@xxxxxxxxxxxxxx>
> > > > pete <pfiland@xxxxxxxxxxxxxx> wrote:
> > > > >No.
> > > > >(void *) is a pointer to an incomplete type,
> > > > >not a pointer to an object type.
> > > >
> > > > Indeed, although "pointer to incomplete [data] type" could be
> > > > considered a sub-group of "pointer to object type", or more
> > > > generically, "data pointer" -- to be distinguished from "function
> > > > pointer", a la Harvard architectures in general.
> > >
> > > No.
> > > In C, there's three kinds of types:
> > > 1 object
> > > 2 incomplete
> > > 3 function
> > >
> > > What Keith Thompson wrote is just simply and completely
> > > accurate and useful to know, as far as C is concerned.
> >
> > 1. That presumes it's possible to assign only one meaning to what
> > Keith wrote.
> >
> > 2. It's common usage in ordinary discussions for "object pointer" to
> > mean a pointer to an object type or to an incomplete type. (Not
> > the only usage, but one common usage.) To pretend otherwise is,
> > well, pretending.
>
> I'm not agreeing.
>
> > I don't know which interpretation Keith intended, but certainly
> > more than one interpretation is possible.
>
> The more obvious interpretation is that there's no definition
> for conversions between object addresses and function addresses.

So you agree that more than one interpretation is possible?
Otherwise saying "the more obvious interpretation" seems like it
doesn't make much sense.


> I don't see any point in contradicting his statement.

I wasn't meaning to contradict his statement, only to clarify it.


> As well as not pointing to any object type
> (void *)0 doesn't point to any object.
> "object pointer" doesn't describe (void *)0
> any better than "function pointer" does.
>
> Tthe relationship between
> (void *)0 and pointers to object types,
> is exactly the same as the relationship between
> (void *)0 and pointers to function types.
>
> There's no special relationship between (void *)0
> concerning objects versus functions.
> null pointers are of both pointer to object types
> and pointer to function types.
>
> (void *) is as much of a function pointer
> as it is an object pointer,
> that is to say "it isn't either".

If you want to take the position that "object pointer" never is
heard or intended to mean anything other than (as language in the
Standard would say it) "pointer to object type", I suppose that's
up to you. It does seem counterproductive though to assume that's
what was meant after it was explicitly stated otherwise.
.



Relevant Pages

  • Re: The usage of %p in C
    ... for void * to have a different size and/or representation ... not just "some pointer". ... void with respect to pointer to any object type. ... and, for example, pointer to int, in the same manner to functions. ...
    (comp.lang.c)
  • Re: Adding to void *
    ... Increasingly often I see C code that adds or substracts integers ... to/from void pointers, like this ... For addition, either both operands shall have arithmetic type, or one operand shall be a pointer to an object type and the other shall have integer type. ...
    (comp.lang.c)
  • Re: Where do pointers point to?
    ... >> absolute guarantee. ... > having the void* type. ... you can pass a void* to a function requiring any form of pointer ... between pointer to any object type and any pointer to function type. ...
    (comp.lang.c)
  • [RFC v8][PATCH 08/12] Infrastructure for shared objects
    ... and also stored in a hash table. ... * @ptr: pointer to object ... * @type: object type ... * fresh unique object reference. ...
    (Linux-Kernel)
  • [RFC v9][PATCH 07/13] Infrastructure for shared objects
    ... and also stored in a hash table. ... * @ptr: pointer to object ... * @type: object type ... * fresh unique object reference. ...
    (Linux-Kernel)