static init function
Saffi Hartal
shartal@artemis.globaloop.com
Wed Aug 26 07:32:00 GMT 1998
I wrote :
I sometimes use that way to init my modules.
ÃÂ if I want to init the arrays and variables i use (i
don't always create a class which supply the interface cause the people around
me use C routines instead of C++ ), what do you think about it.
ÃÂ
static int
init_module(void) { ÃÂ ÃÂ ÃÂ /* code to init the module
*/ ÃÂ ÃÂ ÃÂ return(0); }
ÃÂ
static int init_var=init_module();
ÃÂ ÃÂ ÃÂ Saffi
ÃÂ
Danny answered :
One problem surely exists with this solution: static functions are now
considered deprecated according to the C++ standard. Danny
ÃÂ
I didn't really understood so i asked him for more ...
we answerd :
Here's a more detailed account: In standard C, a function declared
static has an internal linkage, i.e., it is accessible only from within
the translation unit (source file) in which it was declared. Though
still supported in C++, this convention is now considered deprecated.
Therefore, future releases of your C++ compiler may issue a warning message
when finding a static function that is not a member of a class. In
order to make a function accessible only from within the translation unit
in which it is declared, you should use a nameless namespace instead.ÃÂ
//File hidden.cpp namespace { //nameless int init();
//accessible only from within this file } The keyword 'static' was
already used in excess in C++ for various purposes. With the introduction of
namespaces to the language, it seemed more plausible to use that mechanism
to confine the access to identifires which otherwise would be
global. I hope that answers your questions, and sorry if that urges
you to consider revising your existing programs. Of course, you can post
my previous reply as well as this one. Best, Danny
Kalev System analyst and software engineer J16
ÃÂ
ÃÂ ÃÂ ÃÂ I hope that it was also interesting for you.
ÃÂ
ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ
thanks
ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ
by Saffi
More information about the C++-embedded
mailing list