RE: [Dev-C++] What is a static function
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Tomas D. <do...@vo...> - 2001-08-02 15:17:51
|
Hi Albert,
Well, functions declared with static memory class
can't be used in (called from) another module (file) then the one they ar=
e
declared in. It is the same with variables.
Have a look at this...
static void f(void); // this global function and
static int n; // this global variable
// are visible only in the module they are
declared in
Have you got the idea? An easy stuff...
If you want to know what is all this for, just ask.
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...]On Behalf Of
> Albert Vilella Bertran
> Sent: Thursday, August 02, 2001 2:48 PM
> 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 spac=
e
> able to be freed outside of the function?
yes, you can use the memory block and free it, too, if you bring the hand=
ler
of the memory block out of your function.
> How is that "int i" variable managed, is it created always but not use=
d
> unless the "if" condition is true?
it is created always, I deeply believe
functions like this are completely build before they are called
> Can I put this kind of conditional declaration of functions in a
> non-static
> function?
yeah!
>
> I don't know much of it, you see! :)
>
Heh.
Have a good time.
>
> _______________________________________________________________
> 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
>
>
|