File: const.yo

package info (click to toggle)
c%2B%2B-annotations 13.02.02-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,576 kB
  • sloc: cpp: 25,297; makefile: 1,523; ansic: 165; sh: 126; perl: 90; fortran: 27
file content (27 lines) | stat: -rw-r--r-- 1,300 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Static tt(const) hi(static data: const) data members should be initialized
like other static data members: 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-optimizations) 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 (single) source file,
whether or not they are tt(const) data. Additionally, by defining them in a
source file you avoid the inline-inconsistency.