static const char[] public data member missing when -O or puls used (266 Views)
Reply
Occasional Visitor
weili
Posts: 4
Registered: ‎03-28-2011
Message 1 of 6 (266 Views)

static const char[] public data member missing when -O or puls used

I'm facing a problem. I use HP C/aC++ B3910B A.06.20 to compile and build. No error happen in compile time and link time. But in run time, the class public static const char[] data member can't be read. weird thing is when I use debug mood, or -O0 release mood the data member varible value comes back.
Acclaimed Contributor
Dennis Handly
Posts: 25,294
Registered: ‎03-06-2006
Message 2 of 6 (266 Views)

Re: static const char[] public data member missing when -O or puls used

What do you mean "can't be read"? In the debugger or your program aborts?

>-O0 release mode

You should not use +O0, unless +O1 (the default) fails.
Occasional Visitor
weili
Posts: 4
Registered: ‎03-28-2011
Message 3 of 6 (266 Views)

Re: static const char[] public data member missing when -O or puls used

such as you define static const char TAG[]="tag";

when you use TAG. It'll be blank or core dump...
Acclaimed Contributor
Dennis Handly
Posts: 25,294
Registered: ‎03-06-2006
Message 4 of 6 (266 Views)

Re: static const char[] public data member missing when -O or puls used

>when you use TAG it'll be blank or core dump.

I'm not sure how it could be uninitialized.
What type of signal do you get for your abort?
Occasional Visitor
weili
Posts: 4
Registered: ‎03-28-2011
Message 5 of 6 (266 Views)

Re: static const char[] public data member missing when -O or puls used

OK, Let me explain more detailed.
In test.h
class Mytag
{
public:
static const char TAG1[];
static const char TAG2[];
static const char TAG3[];
};
in test.cpp
#include "test.h"
const char Mytag::TAG1[]="tag1";
const char Mytag::TAG2[]="tag2";
const char Mytag::TAG3[]="tag3";
in main.cpp
#include "test.h"
#include
int main()
{
std::cout<<:tag1>
std::cout<<:tag2> std::cout<<:tag3>
return 0;
}

when you compiled with -O or plus.
it'll be a blank printed.

this case may not go wrong.
But My code contains hundreds of TAGS defined. My code fails to run the similar reason as I described above.

thanks in advance


Acclaimed Contributor
Dennis Handly
Posts: 25,294
Registered: ‎03-06-2006
Message 6 of 6 (266 Views)

Re: static const char[] public data member missing when -O or puls used

>But my code contains hundreds of TAGs defined. My code fails to run the similar reason as I described above.

Unfortunately unless we can see how it fails, there isn't much we can do to help.

You may want to patch this to A.06.24, PHSS_40631 (11.31). There was an optimization bug with calculating addresses of data, especially if lots of catches.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.