470,862 Members | 1,731 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,862 developers. It's quick & easy.

C++ construct on AIX

Hi

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:

Here it is:
#include <stdio.h>
class c1
{
public:
char *GetBlah()
{
static char *szPrefix = "ABCD";
return szPrefix;

}

};

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?

Thanks in advance.

-- Henrik
May 30 '06 #1
1 2032
* 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?
May 30 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Lasse Skyum | last post: by
2 posts views Thread by Wiseguy | last post: by
2 posts views Thread by gangesmaster | last post: by
4 posts views Thread by hankssong | last post: by
16 posts views Thread by Ilias Lazaridis | last post: by
11 posts views Thread by lazaridis_com | last post: by
27 posts views Thread by pamela fluente | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.