C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-14-2005, 02:18 PM   #1
1479
 
Join Date: Aug 2003
Posts: 253
Question about Static variables and functions.

What is the different between a function that uses static variables and a static function? I know that a function that has static variables more or less keeps a 'running' total of the variable(s) inside it. What I am confused on is what a static function is meant to do. Is this a static function prototype?
Code:
static int add(int, int);
Or is a function just called static becase it uses static variables? If they are two different things could some one point me in the direction of where I could see some examples? Also, is there a purpose to use a static variable if main() is the only function in the program?
__________________
Knowledge is power and I want it all

-0RealityFusion0-
RealityFusion is offline   Reply With Quote
Old 10-14-2005, 02:27 PM   #2
Code Goddess
 
Prelude's Avatar
 
Join Date: Sep 2001
Posts: 9,661
>What is the different between a function that uses static variables and a static function?
The difference is that static local variables are not deprecated and static functions are. So you shouldn't be using static functions in C++ anyway. But if you must know, a static function has internal linkage instead of the default external linkage. That means that only code from the same translation unit (aka. file after preprocessing) can see and use that function when it's declared as static. The C++ equivalent is an unnamed namespace:
Code:
namespace {
  int add(int, int);
}
__________________
My best code is written with the delete key.
Prelude is offline   Reply With Quote
Old 10-14-2005, 02:31 PM   #3
Even death may die...
 
Dante Shamest's Avatar
 
Join Date: Apr 2003
Location: Malaysia
Posts: 970
http://www.glenmccl.com/stat_cmp.htm
http://www.phim.unibe.ch/comp_doc/c_...TAX/static.htm
Dante Shamest is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
question about static members and functions e66n06 C++ Programming 5 01-07-2008 02:41 PM
Static variables in functions tretton C Programming 1 04-08-2006 06:49 AM
Using private class members in static functions sethjackson C++ Programming 2 09-23-2005 09:54 AM
Static variables and functions problem in a class earth_angel C++ Programming 16 09-15-2005 12:08 PM
Static variables in functions PJYelton C++ Programming 2 10-04-2002 01:41 PM


All times are GMT -6. The time now is 06:06 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22