cppannotations/annotations/yo/static/const.yo
Frank B. Brokken 777b182edd Moved all files but 'excluded', 'sf', and 'sourcetar' to ./annotations
This allowed me to standardize the sourcetar and sf/* scripts: the base
    directory (containing ./git) is now empty, except for maintenance scripts,
    while the source files and build scripts of the annotations are stored in
    a subdirectory of their own.
2013-05-29 20:44:08 +02:00

28 lines
1.2 KiB
Text

Static tt(const) hi(static data: const) data members should be initialized
like any other static data member: in source files defining these data
members.
Usually, if these data members are of integral or built-in primitive data
types the compiler accepts in-class initializations of such data
members. However, there is no formal rule requiring the compiler to do
so. Compilations may or may not succeed depending on the optimizations used by
the compiler (e.g., using tt(-O2) may result in a successful compilation, but
ti(-O0)hi(O0)hi(noopt)
(no-optimalizations) may fail to compile, but then maybe only when shared
libraries are used...).
In-class initializations of integer constant values (e.g., of types tt(char,
int, long), etc, maybe tt(unsigned)) is nevertheless possible using (e.g.,
anonymous) enums. The following example illustrates how this can be done:
verb(
class X
{
public:
enum { s_x = 34 };
enum: size_t { s_maxWidth = 100 };
};
)
To avoid confusion caused by different compiler options static data
members should always explicitly be defined and initialized in a source file,
whether or not tt(const).