473,394 Members | 1,800 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

static function, not a member?

Hi,

I came across some sample code for using a third-party API, and the code
in it had several free-standing (i.e., non-member) functions, but strangely,
these were declared as 'static'. My compiler tells me that the function has
no prototype, which is weird, because there *is* a prototype in the header
file. I was not able to find in my books any reference to a static function
that was not a member function. The closest info I could find (via google)
was something about making the symbol "local", and a suggestion that this
was deprecated in C++.

Can someone tell me what it means to have the static keywoard in front
of a non-member function, and whether it can be safely removed for my use?

Thanks,
Howard

Jul 22 '05 #1
4 1848
"Howard" <al*****@hotmail.com> wrote in message
news:S0******************@bgtnsc05-news.ops.worldnet.att.net
Hi,

I came across some sample code for using a third-party API, and
the code in it had several free-standing (i.e., non-member)
functions, but strangely, these were declared as 'static'. My
compiler tells me that the function has no prototype, which is weird,
because there *is* a prototype in the header file. I was not able to
find in my books any reference to a static function that was not a
member function. The closest info I could find (via google) was
something about making the symbol "local", and a suggestion that this
was deprecated in C++.

Can someone tell me what it means to have the static keywoard in
front of a non-member function, and whether it can be safely removed
for my use?

It means that the function is only available within the translation unit
within which it is defined.

--
John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead)

Jul 22 '05 #2
Howard posted:
Hi,

I came across some sample code for using a third-party API, and the
code
in it had several free-standing (i.e., non-member) functions, but
strangely, these were declared as 'static'. My compiler tells me that
the function has no prototype, which is weird, because there *is* a
prototype in the header file. I was not able to find in my books any
reference to a static function that was not a member function. The
closest info I could find (via google) was something about making the
symbol "local", and a suggestion that this was deprecated in C++.

Can someone tell me what it means to have the static keywoard in
front
of a non-member function, and whether it can be safely removed for my
use?

Thanks,
Howard


EXAMPLE 1

void Horse(void)
{
static int j = 7;

j +=2 ;
}

int main(void)
{
Horse();
Horse();
Horse();
Horse();
Horse();

// The variable j is global, but can only be accessed from
// within the Horse function. Right now, it's value is 17.
}
EXAMPLE 2

static int hello = 45;

int main(void)
{
;
}

The global variable hello cannot be accessed from outside the current CPP
file.

Jul 22 '05 #3
On Mon, 21 Jun 2004 15:29:03 GMT, JKop <NU**@NULL.NULL> wrote in
comp.lang.c++:
Howard posted:
Hi,

I came across some sample code for using a third-party API, and the
code
in it had several free-standing (i.e., non-member) functions, but
strangely, these were declared as 'static'. My compiler tells me that
the function has no prototype, which is weird, because there *is* a
prototype in the header file. I was not able to find in my books any
reference to a static function that was not a member function. The
closest info I could find (via google) was something about making the
symbol "local", and a suggestion that this was deprecated in C++.

Can someone tell me what it means to have the static keywoard in
front
of a non-member function, and whether it can be safely removed for my
use?

Thanks,
Howard


EXAMPLE 1

void Horse(void)
{
static int j = 7;

j +=2 ;
}

int main(void)
{
Horse();
Horse();
Horse();
Horse();
Horse();

// The variable j is global, but can only be accessed from
// within the Horse function. Right now, it's value is 17.
}
EXAMPLE 2

static int hello = 45;

int main(void)
{
;
}

The global variable hello cannot be accessed from outside the current CPP
file.


You misread the question. It dealt with static _functions_, not
static objects.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jul 22 '05 #4
"Howard" <al*****@hotmail.com> wrote in message news:<S0******************@bgtnsc05-news.ops.worldnet.att.net>...
Hi,

I came across some sample code for using a third-party API, and the code
in it had several free-standing (i.e., non-member) functions, but strangely,
these were declared as 'static'. My compiler tells me that the function has
no prototype, which is weird, because there *is* a prototype in the header
file. I was not able to find in my books any reference to a static function
that was not a member function. The closest info I could find (via google)
was something about making the symbol "local", and a suggestion that this
was deprecated in C++.

Can someone tell me what it means to have the static keywoard in front
of a non-member function, and whether it can be safely removed for my use?

Thanks,
Howard

When you add a static keyword in front of a function definition, it
means that the definition of the function would be limited to that
very particular translation unit or that very particular file.
e.g. if your header file includes a lot of functions that you want
your client to use, it is but natural that you do not want to limit
your coding to those very particular functions so you bring in static
functions whose 'usablility' would be reserved to that very particular
translation-unit / file itself only.

--
ISA
isingh AT acm DOT org
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Naren | last post by:
Hello Grp, Correct me if I am wrong. static member functions can act only on static member varaibles.It can accessed by using the name of the class. Then why is there an access controller. ...
29
by: Alexander Mahr | last post by:
Dear Newsgroup, I'm somehow confused with the usage of the static keyword. I can see two function of the keyword static in conjunction with a data member of a class. 1. The data member...
11
by: Roger Leigh | last post by:
The C++ book I have to hand (Liberty and Horvath, Teach yourself C++ for Linux in 21 Days--I know there are better) states that "static member functions cannot access any non-static member...
4
by: raghavendra | last post by:
Hi , A static member can be accessed only by another static method....but the vice-versa is not true....Can anyone pls explain me the logic behind this... Also in a project, if we have too many...
8
by: SJ | last post by:
Hi: I have a class which has a static member function. The function implements something common to all instances. How can the static member function know all of the (Get access to the instances'...
15
by: Samee Zahur | last post by:
Question: How do friend functions and static member functions differ in terms of functionality? I mean, neither necessarily needs an object of the class to be created before they are called and...
5
by: Tony Johansson | last post by:
Hello experts! Why is not possible to have virtual static members Many thnakn //Tony
7
by: jon wayne | last post by:
Hi I'm a little confused here about the lifetime of a static pointer to member function, Say, I declare,define & initialize a static ptr to mem function in the header file of a class(the class...
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
5
by: Michael Oswald | last post by:
Hello all, I'm working on a project where I came across some situations, where the GUI library works with normal C callbacks. The code has been implemented by many people, so I came across...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.