J
John Ratliff
I'm trying to find out whether g++ has a bug or not. Wait, don't leave,
it's a standard C++ question, I promise.
This program will compile and link fine under mingw/g++ 3.4.2, but fails
to link under Linux/g++ 3.3.3.
---------------------------------------------
#include <iostream>
#include <utility>
class foo {
private:
char sram[0x2000];
public:
static const int A = 0x8;
static const int B = 0x1FF8;
foo() {
sram[8] = 1;
sram[9] = 2;
sram[0x1FF8] = 3;
sram[0x1FF9] = 4;
}
std:air<unsigned char, unsigned char> method(bool redundant) const {
int offset = (redundant ? B : A);
return std:air<unsigned char,
unsigned char>(sram[offset], sram[offset + 1]);
}
};
int main(int, char **) {
foo f;
std:air<unsigned char, unsigned char> p1(f.method(false));
std:air<unsigned char, unsigned char> p2(f.method(true));
std::cout << "p1 = (" << (int)p1.first << ","
<< (int)p1.second << ")\n";
std::cout << "p2 = (" << (int)p2.first << ","
<< (int)p2.second << ")\n";
return 0;
}
---------------------------------------------
The reason is that in mingw/g++ 3.4.2, the static constants A and B are
replaced during compile time and didn't need storage space. The linker
therefore didn't need to find them. However, Linux/g++ 3.3.3 generates
code that requires them to have storage space.
Am I supposed to declare storage space for these constants, or is it
legal here to assume they will become compile-time constnats? What does
the C++ standard say?
Thanks,
--John Ratliff
it's a standard C++ question, I promise.
This program will compile and link fine under mingw/g++ 3.4.2, but fails
to link under Linux/g++ 3.3.3.
---------------------------------------------
#include <iostream>
#include <utility>
class foo {
private:
char sram[0x2000];
public:
static const int A = 0x8;
static const int B = 0x1FF8;
foo() {
sram[8] = 1;
sram[9] = 2;
sram[0x1FF8] = 3;
sram[0x1FF9] = 4;
}
std:air<unsigned char, unsigned char> method(bool redundant) const {
int offset = (redundant ? B : A);
return std:air<unsigned char,
unsigned char>(sram[offset], sram[offset + 1]);
}
};
int main(int, char **) {
foo f;
std:air<unsigned char, unsigned char> p1(f.method(false));
std:air<unsigned char, unsigned char> p2(f.method(true));
std::cout << "p1 = (" << (int)p1.first << ","
<< (int)p1.second << ")\n";
std::cout << "p2 = (" << (int)p2.first << ","
<< (int)p2.second << ")\n";
return 0;
}
---------------------------------------------
The reason is that in mingw/g++ 3.4.2, the static constants A and B are
replaced during compile time and didn't need storage space. The linker
therefore didn't need to find them. However, Linux/g++ 3.3.3 generates
code that requires them to have storage space.
Am I supposed to declare storage space for these constants, or is it
legal here to assume they will become compile-time constnats? What does
the C++ standard say?
Thanks,
--John Ratliff