Can a function return a pointer to itself?

This is a discussion on Can a function return a pointer to itself? within the C Programming forums, part of the General Programming Boards category; Can a function return a pointer to itself or another function of the same type (same arguments and return value)? ...

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    2,021

    Can a function return a pointer to itself?

    Can a function return a pointer to itself or another function of the same type (same arguments and return value)?

    Logically, there should be nothing preventing it. However, syntactically, I can't think of a way to do this.

  2. #2
    Mad OnionKnight's Avatar
    Join Date
    Jan 2005
    Location
    Umeň, Sweden
    Posts
    555
    I can think of returning the function pointer as a void pointer but I don't see how it would be useful.

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    2,021
    I thought of that. Surely there is a more direct aproach though.

    The point of this is to have a process queue, where each function is executed then gets put on the queue. When a certain function is called, the queue is restarted to a certian point, meaning that the program starts reading from that point. Essentially, the point is to create a custom while loop that does not require a closing brace.

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by King Mir
    Can a function return a pointer to itself or another function of the same type (same arguments and return value)?

    Logically, there should be nothing preventing it. However, syntactically, I can't think of a way to do this.
    http://c-faq.com/decl/recurfuncp.html
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Registered User
    Join Date
    Apr 2006
    Posts
    2,021
    Thank you!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  3. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 07:05 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21