Thread: just a random question

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Quote Originally Posted by ripper079 View Post
    Code:
    void test()
    {
    	return ;
    }
    compiles fine...

    Is it possible to "return ;" in a function that return void???
    Yes, and it's oftentimes very useful:
    Code:
    void func()
    {
      if(!condition)
        return;
    
      // Several lines of code follow
    }
    If you couldn't return; then the several lines of code would have to be contained in the if(), which IMHO, makes the function harder to read.
    If you understand what you're doing, you're not learning anything.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by itsme86 View Post
    If you couldn't return; then the several lines of code would have to be contained in the if(), which IMHO, makes the function harder to read.
    Heh. That reminds me of Microsoft:
    Code:
    if (SUCCEEDED(hr)
    {
    	//...
    	if (SUCCEEDED(hr)
    	{
    		//...
    		if (SUCCEEDED(hr)
    		{
    			//...
    			if (SUCCEEDED(hr)
    			{
    				//...
    				// and so on
    			}
    		}
    	}
    }
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. random question program
    By rogster001 in forum C++ Programming
    Replies: 1
    Last Post: 10-08-2009, 02:29 AM
  2. Another brain block... Random Numbers
    By DanFraser in forum C# Programming
    Replies: 2
    Last Post: 01-23-2005, 05:51 PM
  3. How do I restart a random number sequence.
    By jeffski in forum C Programming
    Replies: 6
    Last Post: 05-29-2003, 02:40 PM
  4. Noob question for random number
    By SKINp in forum C++ Programming
    Replies: 6
    Last Post: 01-03-2003, 12:53 PM
  5. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 03:57 PM

Tags for this Thread