• Re: function pointer question

    From Tim Rentsch@3:633/10 to All on Fri Jan 9 09:14:22 2026
    James Kuyper <jameskuyper@alumni.caltech.edu> writes:

    On 2026-01-06 07:32, Michael Sanders wrote:

    On Mon, 5 Jan 2026 08:39:53 -0000 (UTC), Michael Sanders wrote:

    I might have questions down the road...

    In the message you were responding to, I was talking about declarations,
    not expressions.

    One more question, but 1st the context...

    I asked ChatGPT this question:

    In C, what is the most common meaning of (void) *foo

    I'm curious - in what context did you encounter that code? As written,
    it's an expression, and foo would have to be a pointer to an object,

    That statement is simply wrong. The identifier foo could name a
    function, or be of type pointer to function, or be of type pointer
    to an object type (and whose value might or might not point to an
    object). A compiler might issue a diagnostic if foo has a type
    that is a pointer to an incomplete object type, but ABICD the C
    standard doesn't actually require that; the constraint says that
    the operand "shall have pointer type".

    which would be a change of subject from the previous messages in this
    thread.

    However,

    (void) *foo;

    would be a declaration equivalent to

    void *foo;

    which is a pointer to void, which would fit the context of our previous discussion. Could that be what you're actually asking about?

    In what context is '(void) *foo;' considered a declaration?
    AFAICT it doesn't satisfy the syntax rules of any version
    of ISO C.

    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Andrey Tarasevich@3:633/10 to All on Sat Jan 10 19:17:35 2026
    On Tue 1/6/2026 7:58 AM, James Kuyper wrote:

    However,

    (void) *foo;

    would be a declaration equivalent to

    void *foo;

    which is a pointer to void, which would fit the context of our previous discussion. Could that be what you're actually asking about?

    Um... I believe Tim Rentsch is correct in stating that C declaration
    syntax does not allow this. When it comes to 'declaration-specifiers'
    portion of the declaration, the grammar is pretty strict in not allowing
    and redundant parentheses to slip through. You can't simply parenthesize
    the type name and still expect it to match the 'declaration-specifiers' grammar.

    The 'init-declarator-list' side is way more permissive in that regard

    int (a); /* equivalent to `int a;` */

    but not what you stated above.

    P.S. On a loosely related note: the C++-like grammatical ambiguity
    between a function call and a declaration, present in

    { foo(x); }

    is technically present in C as well, but it is prevented by the fact
    that there's simply no way to declare `foo` as a function and as a
    typedef name without having one name hide another.

    --
    Best regards,
    Andrey

    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From James Russell Kuyper Jr.@3:633/10 to All on Sat Jan 10 22:39:37 2026
    On 2026-01-10 22:17, Andrey Tarasevich wrote:
    On Tue 1/6/2026 7:58 AM, James Kuyper wrote:

    However,

    ÿÿÿÿÿ (void) *foo;

    would be a declaration equivalent to

    ÿÿÿÿ void *foo;

    which is a pointer to void, which would fit the context of our previous
    discussion. Could that be what you're actually asking about?

    Um... I believe Tim Rentsch is correct in stating that C declaration
    syntax does not allow this. When it comes to 'declaration-specifiers' portion of the declaration, the grammar is pretty strict in not allowing
    and redundant parentheses to slip through. You can't simply parenthesize
    the type name and still expect it to match the 'declaration-specifiers' grammar.

    The 'init-declarator-list' side is way more permissive in that regard

    ÿ int (a); /* equivalent to `int a;` */

    but not what you stated above.

    P.S. On a loosely related note: the C++-like grammatical ambiguity
    between a function call and a declaration, present in

    ÿ { foo(x); }

    is technically present in C as well, but it is prevented by the fact
    that there's simply no way to declare `foo` as a function and as a
    typedef name without having one name hide another.


    I had remembered that parantheses could be optionally (and pointlessly)
    added surrounding a declarator (6.7.7.1p6). Since it's a feature I would
    never bother using, I didn't pay much attention to the details, and
    forgot that it applies only to the declarator. I should have checked
    before posting.


    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Tim Rentsch@3:633/10 to All on Sun Jan 11 11:49:03 2026
    Andrey Tarasevich <noone@noone.net> writes:

    On Tue 1/6/2026 7:58 AM, James Kuyper wrote:

    However,

    (void) *foo;

    would be a declaration equivalent to

    void *foo;

    which is a pointer to void, which would fit the context of our previous
    discussion. Could that be what you're actually asking about?

    Um... I believe Tim Rentsch is correct in stating that C declaration
    syntax does not allow this. [...]

    Thanks Andrey. :)

    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)