473,394 Members | 1,739 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.

What does this static function mean?

Hi All
I read a .cpp files,find that
static void fun(void){......}

int main()
{
..........
}

What does this static function mean?Is it the same as the static
function in a class?
Thanks

Nov 5 '07 #1
4 5288
dolphin <jd*******@gmail.comwrites:
>Hi All
I read a .cpp files,find that
static void fun(void){......}
...
>What does this static function mean?
See
http://www-h.eng.cam.ac.uk/help/tpl/...++/static.html
Nov 5 '07 #2
dolphin a ¨¦crit :
I read a .cpp files,find that
static void fun(void){......}

int main()
{
.........
}

What does this static function mean?Is it the same as the static
function in a class?
Technically, this means the name of the function won't be exported so
you can reuse it in more than one compilation unit.

From the programmer point of view, this means the function won't be
called by tis name outside the compilation unit.

An alternative is to use an unnamed namespace.

Michael
Nov 5 '07 #3
On Nov 5, 4:57 pm, Michael DOUBEZ <michael.dou...@free.frwrote:
dolphin a écrit :
I read a .cpp files,find that
static void fun(void){......}
int main()
{
.........
}
What does this static function mean?Is it the same as the static
function in a class?

Technically, this means the name of the function won't be exported so
you can reuse it in more than one compilation unit.

From the programmer point of view, this means the function won't be
called by tis name outside the compilation unit.

An alternative is to use an unnamed namespace.

Michael
Do you mean you just can use this function in that cpp file?And you
cannt use it in another cpp file?

Nov 5 '07 #4
dolphin a écrit :
On Nov 5, 4:57 pm, Michael DOUBEZ <michael.dou...@free.frwrote:
>dolphin a écrit :
>>I read a .cpp files,find that
static void fun(void){......}
int main()
{
.........
}
What does this static function mean?Is it the same as the static
function in a class?
Technically, this means the name of the function won't be exported so
you can reuse it in more than one compilation unit.

From the programmer point of view, this means the function won't be
called by tis name outside the compilation unit.

An alternative is to use an unnamed namespace.

Do you mean you just can use this function in that cpp file?And you
cannt use it in another cpp file?
What I mean is that the name of the function is not exported in the
symbol table so you cannot link against it outside the cpp file it is
defined in.
That doesn't mean it cannot be used, you could use through is function
pointer by example. But not with its name. Try it out on an example.
main.cpp
-----------------------
extern int cu_function();

int main()
{
return cu_function();
}

cu.cpp
-----------------------
//uncomment static to see what happen
//static
int cu_function()
{
return 0;
}
-----------------------

Then
g++ main.cpp cu.cpp

Michael
Nov 5 '07 #5

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

Similar topics

2
by: Steve Richter | last post by:
What does the "." mean in the following sql script stmts? use GO if exists (select * from dbo.sysobjects where id = object_id(N'.') and OBJECTPROPERTY(id,N'IsUserTable') = 1) drop table ....
3
by: RobertTG | last post by:
Someone please translate the code below into English... Particularly the indicated line Thanks function attachComment() { var aForms = document.getElementsByTagName("FORM"); for (var i = 0;...
6
by: allenj | last post by:
DB21085I Instance "md" uses "32" bits and DB2 code release "SQL08012" with level identifier "02030106". Informational tokens are "DB2 v8.1.0.16", "s030508", "MI00048", and FixPak "2". Product is...
58
by: Larry David | last post by:
Ok, first of all, let's get the obvious stuff out of the way. I'm an idiot. So please indulge me for a moment. Consider it an act of "community service".... What does "64bit" mean to your friendly...
92
by: Heinrich Pumpernickel | last post by:
what does this warning mean ? #include <stdio.h> int main() { long l = 100; printf("l is %li\n", l * 10L);
2
by: priyain | last post by:
hello, Can anyone explain me what is static function in c with example ? also where it is used ?
45
by: loudking | last post by:
Hello, all I don't quite understand what does ((time_t)-1) mean when I execute "man 2 time" RETURN VALUE On success, the value of time in seconds since the Epoch is retu rned. On error,...
1
by: dayanand50 | last post by:
ii wanted to know what is static function in java and how to declare it
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.