Operating System - HP-UX
1748165 Members
3790 Online
108758 Solutions
New Discussion юеВ

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

 
weili
New Member

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.
5 REPLIES 5
Dennis Handly
Acclaimed Contributor

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.
weili
New Member

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...
Dennis Handly
Acclaimed Contributor

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?
weili
New Member

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


Dennis Handly
Acclaimed Contributor

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.