Thread: Functions&Returnvalues

  1. #1
    Politics&Cpp geek Da-Nuka's Avatar
    Join Date
    Oct 2004


    ...When i make a function, which shall maybe do something like modify a global variable, it is no need to declear the function with a return value.

    But is it a good habit to let all functions have return values?
    And if I should give even this function a return value, is it important to check it from the main() as well?

  2. #2
    Registered User
    Join Date
    Feb 2005

    i dont think so

    hello, im just a 2nd year uni student who's doing mechtronics engineering at the university of sydney, i learned C at last semester, so it's just my own idea:

    i dont think return values are necessary, but it really depends on wat situation.

    true, my lecturer says it's a good habit, cos when we get into a company and doing some software design, we must make sure the program is working properly, that's why the return values are useful.

    if the function is having an error, we could check the return values, to print out an error message or teminate the program immediately, that's wat i think.

    last words, i had a 3 months holiday, so i havent been touching C for 3 months, so....

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Oregon, USA
    I don't think it really has anything to do with good form. If the function requires a return value then it should have one. If it doesn't need one then it shouldn't have one. Making a function return a value for no reason just leads to confusion when someone reads your code and tries to figure out why your function is returning something that no calling function actually uses or cares about.

    You might want to rethink your program design though. You generally want to avoid global variables.
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed