Thread: function task exit

  1. #1
    Registered User
    Join Date
    Apr 2015
    Posts
    500

    function task exit

    Hi , I'm wondering whenever I have a function with specific task lets say the task to our analogues life drinking water , how does the PC knows that the function/task is terminated?! meaning whenever I finish the task how the compiler knows that the task is terminated? is there any command that the compiler is depending on and sending it to the CPU for letting it knows that task is finished successfully?
    because it's really weird how the compiler work.


    thanks for your help again

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    26,440
    Perhaps if you posted example code that you're puzzling about instead of an "analogy from real life", we could have a basis for explanation. If not, my answer from analogy would be: "anyone can see that I've finished drinking the water, duh!"
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User Kernelpanic's Avatar
    Join Date
    Sep 2018
    Location
    Berlin
    Posts
    103
    Quote Originally Posted by RyanC View Post
    . . .
    because it's really weird how the compiler work.
    If you want know how a compiler work: Learning by doing!

    Compilers: Amazon.de: Alfred V. Aho, Ravi Sethi, Jeffrey D. Ullman: Fremdsprachige Bucher

  4. #4
    Registered User
    Join Date
    Apr 2015
    Posts
    500
    Quote Originally Posted by laserlight View Post
    Perhaps if you posted example code that you're puzzling about instead of an "analogy from real life", we could have a basis for explanation. If not, my answer from analogy would be: "anyone can see that I've finished drinking the water, duh!"
    Maybe I didn't clear it well, but I'm meaning whenever a function is done and all alright, how CPU knows that the function has been successfully finished?! for example, lets assume there is a function
    Code:
    void doing_something()
    {
       printf("Hello world");
    }
    whenever I call the function the pc will read what's inside the function, my question is how does he know that he arrived to the end of the function successfully ?!


    thanks!

  5. #5
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    573
    Quote Originally Posted by RyanC View Post
    whenever I call the function the pc will read what's inside the function, my question is how does he know that he arrived to the end of the function successfully ?!
    The compiler tells the computer where the function ends. This is usually done with some type of "return from subroutine" instruction to go back to the calling function.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Advanced task, implementing a function :]
    By chongmet in forum C Programming
    Replies: 18
    Last Post: 11-03-2014, 10:23 AM
  2. specific task function
    By XodoX in forum C++ Programming
    Replies: 7
    Last Post: 03-01-2009, 12:44 PM
  3. Replies: 2
    Last Post: 12-31-2007, 11:40 AM
  4. about exit() function
    By deian in forum C Programming
    Replies: 1
    Last Post: 10-20-2004, 12:34 PM
  5. Exit a function
    By MasterGBC in forum C Programming
    Replies: 3
    Last Post: 04-10-2003, 10:46 PM

Tags for this Thread