🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: csu.cs.200
Article #372

Re: Basic C++ question

#372
From: Corby S. Hudnall
Date: Wed, 04 Feb 1998 00:00
44 lines
2302 bytes
You are mostly correct but there is one notable mistake with your
response.  'void' functions can have an empty return statement in them
and will NOT produce a syntax error.  This is so that the control flow
of a function can be governed.   Consider, for example, a function that
swaps the values of two pointers (not unlike what SelSort does for the
current assignment):

void swap( Node* src1, Node* src2 )
{
	if( src1 == src2 )
		return;  //  <-- if the nodes are the same, I don't want
			 //       to do anything, and just return.

	etc....
}

As for placing prototypes in functions, that too is just fine and is in
fact preferable to placing prototypes in global space whenever
possible.  I didn't mention that because in truth, we'll be using c++
classes for later assignments, at which time the notion of a free
function (one outside of a class) becomes largely unused.


michael maitan wrote:
> 
>   I wanted to point out that function prototypes can be placed in functions
> as well.  This is useful if you do not want them to be global. In some of the
> programs in CS151 we were actually required to place the prototypes in
> the main() function.  I also noticed there were ruturn statements in the
> functions used. Since the functions were defined with void before the
> function name, the function is not expected to return anything through its
> name.  This will cause a syntax error when compiled. (Ex. void function()
> returns nothing through its name...  int function2() returns an int through
> its name)  I hope this is of help to any who read this. : )
> 
> -Mike
> (http://holly.colostate.edu/~brnruber)


cheers
--
Corby S. Hudnall
http://www.cs.colostate.edu/~hudnall/cs200
Technical Details
Message-ID: <34D8A66A.EC5AFDBC@cs.colostate.edu>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <6b92v9$2pvs@yuma.ACNS.ColoState.EDU>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 127144,f08d1a1544bcc5dc
X-Google-Attributes: gid127144,public
From: "Corby S. Hudnall" <hudnall@cs.colostate.edu>
Subject: Re: Basic C++ question
Date: 1998/02/04
Message-ID: <34D8A66A.EC5AFDBC@cs.colostate.edu>
X-Deja-AN: 322047484
Content-Transfer-Encoding: 7bit
References: <6b92v9$2pvs@yuma.ACNS.ColoState.EDU>
Mime-Version: 1.0
To: michael maitan <maitan@cs.colostate.edu>
Content-Type: text/plain; charset=us-ascii
Organization: Colorado State University
Newsgroups: csu.cs.200