473,386 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 2134
* 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Lasse Skyum | last post by:
I'm currently learning STL and I hate not knowing what is gooing on "inside" STL... not because I really _need_ to know it to develop my game project, but that's just my nature... like most of you...
2
by: Wiseguy | last post by:
I'm in the process of trying to create my own lean, mean, uber linux distro and have bootstrapped a prototype system to build upon. I'm using the gcc 3.4.3 compiler and am getting an error that I...
0
by: Laser Lu | last post by:
Hi, all, Does any body know how to use this Grouping Construct? (?> ) The following is its description in the MSDN reference: Nonbacktracking subexpression (also known as a "greedy"...
12
by: Laser Lu | last post by:
Hello, everybody, do you know how to use this Grouping Construct? (?> ) I've found its reference on MSDN, but still can not understand it totally. The following is its description: ...
17
by: Mike Hofer | last post by:
While I'd toyed with C, C++, and Java over the last 20 years or so, my principal language has been BASIC, QBASIC, then Visual Basic, and finally Visual Basic .NET. But lately, I've been using C#...
2
by: gangesmaster | last post by:
finally, i opened a wiki for Construct, the "parsing made fun" library. the project's page: http://pyconstruct.sourceforge.net/ the project's wiki: http://pyconstruct.wikispaces.com/ (anyone can...
4
by: hankssong | last post by:
Hi everyone, I'm wondering whether it's possible to construct a binary-tree using python. Since python don't have pointer, it can't dynamically allocate memory like C language. But some important...
16
by: Ilias Lazaridis | last post by:
I have a few small questions subjecting python functionality, most importantly the "alias_method". - *IMPORT* I would like to know, if this construct is valid, or if it can result in...
11
by: lazaridis_com | last post by:
I would like to change the construct: if __name__ == '__main__': to something like: if exec.isMain(): My (OO thought) is to place a class in an separate code module and to instantiate an...
27
by: pamela fluente | last post by:
Hello, for the following code, VS suggests that construct (width= height= ) is out of date and a newer one is recommended: <table><tr><td width="92" height="38" valign="middle">AnyThing</td></...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.