* Henrik Goldman:
I have a C++ construct which works fine on a number of platforms. However on
AIX using g++ 3.3.2 it gives a warning:
#include <stdio.h>
class c1
{
public:
char *GetBlah()
{
static char *szPrefix = "ABCD";
return szPrefix;
}
};
Indentation would be nice.
int main()
{
c1 c;
printf("%s\n", c.GetBlah());
return 0;
}
What I get is:
test2.cpp: In member function `char* c1::GetBlah()':
test2.cpp:11: warning: sorry: semantics of inline function static data `
char*szPrefix' are wrong (you'll wind up with multiple copies)
test2.cpp:11: warning: you can work around this by removing the
initializer
Isn't this valid code?
AFAICS it is (although the lack of indentation makes it difficult to
see), but only because of the C compatibity that allows you to
initialize a char* with a literal string; I'd make that a char const*.
There have been a number of postings pointg out errors in AIX C++
compilers (possibly the same compiler), and I think the warning with
"sorry" is a way to tell you the compiler folks knew that this was wrong
behavior, but didn't have the time to fix it.
Perhaps upgrade the compiler, if possible? Alternatively, put that
function in an implementation file, compiled separately.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?