Thread: Return void or success/fail?

  1. #16
    Anal comment spacer DominicTrix's Avatar
    Join Date
    Apr 2002
    Posts
    120
    Plenty of two cents here I know, but mine are:

    I only return a status variable when using Dynamic Memory Allocation, when accessing files, or any other time when errors may be beyond the control of the coder.

    I return an integer, 1 or 0. This works the same as BOOL and looks prettier to me (I like pretty things

    I think the advantage is small, in that your error checking code is shorter, i.e.

    Code:
       if(!MyFunction())
       {
          // do error handling
          ...
    
    
    // as opposed to
    
       int success;
       MyFunction(success);
       if(!success)
       {
          // do error handling
          ...
    The latter is easier to read although it makes more 'if' nests in the function/ procedure itself.
    I guess it really is just preference.

    dt
    Last edited by DominicTrix; 09-01-2004 at 07:25 PM. Reason: typo in code
    "The most important thing about acting is honesty. If you can fake that you've got it made" - George Burns

  2. #17
    Registered User
    Join Date
    Jul 2003
    Posts
    450
    I agree I prefer to use the function as a status variable be it boolean or integer rather than using the status variable as a parameter to the function.

    Just my two cents.


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How can I make this code more elegant?
    By ejohns85 in forum C++ Programming
    Replies: 3
    Last Post: 04-02-2009, 08:55 AM
  2. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  3. need help program crashing
    By tunerfreak in forum C++ Programming
    Replies: 14
    Last Post: 05-22-2006, 11:29 AM
  4. Replies: 2
    Last Post: 03-24-2006, 08:36 PM
  5. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM