what is this declaration?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • 1230987za@gmail.com

    what is this declaration?

    Hi,

    I was reading a post about how to learn C programming and someone
    mentioned this, *(int f()) in a struct. It is not in any C code, I
    guess the guy was showing that there are some tricky part in C.

    It does look tricky to me, what does it mean?

    Is the following correct?

    f is a function; the function returns an integer; this integer is de-
    referenced just like a function pointer.

    Can someone show me an example usage of such declaration?
  • pete

    #2
    Re: what is this declaration?

    1230987za@gmail .com wrote:
    Hi,
    >
    I was reading a post about how to learn C programming and someone
    mentioned this, *(int f()) in a struct. It is not in any C code, I
    guess the guy was showing that there are some tricky part in C.
    >
    It does look tricky to me, what does it mean?
    >
    Is the following correct?
    >
    f is a function; the function returns an integer; this integer is de-
    referenced just like a function pointer.
    >
    Can someone show me an example usage of such declaration?
    It needs more context.
    What you've shown is neither a declaration nor an expression
    nor any other C construct that I'm familiar with.

    --
    pete

    Comment

    • Old Wolf

      #3
      Re: what is this declaration?

      On Jun 22, 4:31 pm, 123098...@gmail .com wrote:
      I was reading a post about how to learn C programming and someone
      mentioned this, *(int f()) in a struct. It is not in any C code, I
      guess the guy was showing that there are some tricky part in C.
      This is not a valid declaration ; perhaps you
      are remembering it wrongly.
      f is a function; the function returns an integer; this integer is de-
      referenced just like a function pointer.
      Integers cannot be dereferenced.

      A function returning int would be:
      int f();
      which cannot occur in a struct definition.

      A pointer to function returning int would be:
      int (*f)();

      Comment

      • rahul

        #4
        Re: what is this declaration?

        On Jun 22, 9:31 am, 123098...@gmail .com wrote:
        Hi,
        >
        I was reading a post about how to learn C programming and someone
        mentioned this, *(int f()) in a struct. It is not in any C code, I
        guess the guy was showing that there are some tricky part in C.
        >
        It does look tricky to me, what does it mean?
        >
        Is the following correct?
        >
        Does not look like it can be correct in any context.
        f is a function; the function returns an integer; this integer is de-
        referenced just like a function pointer.
        That does not make any sense at all.


        Comment

        Working...