Thread: Function help

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    17

    Function help

    Is it possible to have a function that returns a value when one function calls it but doesn't return a value when some other function calls it?

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Not in C.

    If you don't want the value being returned at any time, just don't "catch" the value, and it will be lost when the function returns.

    result = myFunction(); //value returned is caught by "result" variable
    myFunction(); //value returned is immediately lost

    Make sense?

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    17
    I thought if a function returns something then you must catch it?

  4. #4
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Quote Originally Posted by gar35 View Post
    I thought if a function returns something then you must catch it?
    You don't have to. Presumably if you have a function that returns a value that value probably has a meaning or some use. For example scanf() has a return value too, however often times it is ignored.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling C in Visual Studio 2005
    By emanresu in forum C Programming
    Replies: 3
    Last Post: 11-16-2009, 04:25 AM
  2. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  3. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM