Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > C++ construct on AIX

Reply
Thread Tools

C++ construct on AIX

 
 
Henrik Goldman
Guest
Posts: n/a
 
      05-30-2006
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


 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      05-30-2006
* 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?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Behavior of if construct in switch case defualt construct. Mukesh C Programming 4 03-26-2010 12:38 PM
putenv for AIX and ifdef for AIX ClownPleco C Programming 5 08-24-2007 02:15 PM
Looking for AIX 5.2 binaries, IS anyone running Ruby on AIX 5.2 ?? bww00amdahl@yahoo.com Ruby 5 07-08-2005 11:54 AM
Construct synthesis problem Kuan Zhou VHDL 2 04-22-2005 08:51 AM
VHDL correspondance of Verilog construct Floresita VHDL 3 04-02-2004 01:43 PM



Advertisments