C++ construct on AIX

Discussion in 'C++' started by Henrik Goldman, May 30, 2006.

  1. 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
    Henrik Goldman, May 30, 2006
    #1
    1. Advertising

  2. * 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?
    Alf P. Steinbach, May 30, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Floresita
    Replies:
    3
    Views:
    5,441
    Oggie
    Apr 2, 2004
  2. Kuan Zhou

    Construct synthesis problem

    Kuan Zhou, Apr 22, 2005, in forum: VHDL
    Replies:
    2
    Views:
    511
    Mohammed A khader
    Apr 22, 2005
  3. ClownPleco

    putenv for AIX and ifdef for AIX

    ClownPleco, Aug 22, 2007, in forum: C Programming
    Replies:
    5
    Views:
    1,101
    Thomas Dickey
    Aug 24, 2007
  4. Mukesh
    Replies:
    4
    Views:
    604
    Paul N
    Mar 26, 2010
  5. Replies:
    5
    Views:
    183
    Philippe Lucas
    Jul 8, 2005
Loading...

Share This Page