RE: [Dev-C++] What is a static function
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Dave H. <dhe...@ch...> - 2001-08-02 19:05:12
|
I may be able to help you out some...
Any function that is declared "static" cannot be called by any routine th=
at
is not contained in the same source file. If you were to have two files,
"main.cpp" and "bv.cpp", in your project, and initBV() was contained in
"bv.cpp" and declared as "static", functions in "main.cpp" would not be a=
ble
to call it.
It boils down to whether or not the function handle "initBV" ends up in t=
he
global symbol table used by the linker. If it's declared "static", the
handle won't be in the table, and the linker won't be able to resolve it.
This is good for limiting scope of callability when you don't have C++
classes with private elements. You might compare it to a private method =
in
a class.
The function itself exists and is compiled just as any other function.
Consequently, the variable "i" will be put on the stack with any other lo=
cal
variables.
Hope this helps,
Dave
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...]On Behalf Of Albert
Vilella Bertran
Sent: Thursday, August 02, 2001 7:48 AM
To: dev...@li...
Subject: [Dev-C++] What is a static function
I don't understand what is like to declare a function as "static".
For example:
static void initBV() {
if (!inittedBV)
{
int i;
for (i=3D0; i<ArraySize(bV); i++)
bV[i] =3D -1;
bV['a'] =3D bV['A'] =3D A_B_V;
bV['b'] =3D bV['B'] =3D B_B_V;
bV['c'] =3D bV['C'] =3D C_B_V;
bV['d'] =3D bV['D'] =3D D_B_V;
bV['e'] =3D bV['E'] =3D E_B_V;
inittedBV =3D TRUE;
}
}
What is that code doing?
If I "malloc" something inside the function, what happens? Is the space
able to be freed outside of the function?
How is that "int i" variable managed, is it created always but not used
unless the "if" condition is true?
Can I put this kind of conditional declaration of functions in a non-stat=
ic
function?
I don't know much of it, you see! :)
_______________________________________________________________
Do You Yahoo!?
Yahoo! Messenger: Comunicaci=F3n instant=E1nea gratis con tu gente -
http://messenger.yahoo.es
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
http://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|