This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: static const double pi = 3.1415;
On Thu, Feb 20, 2003 at 10:25:00PM +0200, Kai Henningsen wrote:
> Exhibit 1:
>
> static sometype = someexpression;
>
> Exhibit 2:
>
> class foo {
>
> static sometype = someexpression;
>
> [...]
> };
>
> What is the justification for putting stronger requirements on the Exhibit
> 2 case than on the Exhibit 1 case? (That is, why does the standard make a
> difference here?)
A.h:
static double x;
struct A {
static double y;
};
A.cc:
#include "A.h"
double A::y;
b1.cc:
#include "A.h"
double *b1x() { return &x; }
double *b1y() { return &a::y; }
b2.cc:
#include "A.h"
double *b2x() { return &x; }
double *b2y() { return &a::y; }
main.cc:
#include <stdlib.h>
extern double *b1x(), *b1y(), *b2x(), *b2y();
int main()
{
assert(b1x() != b2x());
assert(b1y() == b2y());
return 0;
}
Modulo typos, this program should work. "const" makes zero difference.
OG.