Does anyone know what the most specific newsgroup I could go to for HPUX c programming with the cc compiler? Or if anyone here has experience with HPUX, I'll post here...Thanks.
Printable View
Does anyone know what the most specific newsgroup I could go to for HPUX c programming with the cc compiler? Or if anyone here has experience with HPUX, I'll post here...Thanks.
There's comp.unix.programmer and comp.sys.hp.hpux
www.tek-tips.com
Search for "hp-ux"
I have a few HP-UX boxes to hand, but I don't program on them as a rule. If you want to post your questions here, do so, and someone will try to help you.Quote:
Originally posted by IfYouSaySo
Does anyone know what the most specific newsgroup I could go to for HPUX c programming with the cc compiler? Or if anyone here has experience with HPUX, I'll post here...Thanks.
I run the following program:
Stepping through in the debugger, I find that SSInstance is initialized to garbage. Its almost as if the memory address of array has not been assigned an address yet. With some experimenting, I find that if I do not initialize some_var ( ie. int some_var; /* = 345; */ ) then the code will initialize properly. This is true for any initialization of static global data in the file.Code:
int some_var = 345;
int main()
{
struct { int x; char array[32]; } X = { 0 };
struct SomeStruct { char* p; } SSInstance = { X.array };
return 0;
}
This seems like a bug. But is there something that I am doing which is not correct c, if I follow the standard strictly? The code works on MSVC5, Tru64Unix, & Intel x86 Linux.
Thanks.
My compiler won't let me initialise like that, I'd do it this way:
What you're doing is probably non-standard, I'll try to dig out some documentation later, unless someone beats me to it...Code:int some_var = 345;
int main()
{
struct { int x; char array[32]; } X = { 0 };
struct SomeStruct { char* p; } SSInstance ;
SSInstance.p = X.array;
return 0;
}
On the hp newsgroup, someone said that it is a c99 extension, because I am initializing a structure with a non-const. It turns out that I cannot do it as you recommend, because I need the whole thing to act as if it is initializing a single type. In other words, I need to be able to put multiple structure initializations one after the other at the top of a function call, which will not be possible if I add the assignment statement SSInstance.p = X.array;
If someone is able to say for sure that this is non-standard or implementation-specific, I would like to know. Thanks.
Yes, it's because it needs to be a const value.
Why do you have to do that?Quote:
It turns out that I cannot do it as you recommend, because I need the whole thing to act as if it is initializing a single type. In other words, I need to be able to put multiple structure initializations one after the other at the top of a function call, which will not be possible if I add the assignment statement SSInstance.p = X.array;
I'll repeat it again: initializing to a non const is supposedly a c99 extension.
Why do I have to do it like that? Because I'm porting thousands of lines of code, and it's doing these initializations all over the place, and it works on 4 or 5 other platforms, and because "It doesnt work on HP so I'm going to change all the code" probably won't fly when my boss asks me at the weekly meeting. That's why. So work with me here.
IfYouSaySo - do you get any compiler warnings when you compile that code?
I'm reasonably sure that what you're trying to do is C89. I compiled it with "gcc -ansi -pedantic -Wall cpr-test.c", and gcc is pretty good at spotting non-standard things with those two flags.
I know the standard talks about const initialisers, but to my mind a pointer to another variable (albeit a local) should be const enough. The spirit of the standard is to prevent things like this
struct SomeStruct { char* p; } SSInstance = { some_function_call_returning_char_pointer() };
> I find that if I do not initialize some_var ( ie. int some_var; /* = 345; */ ) then the code will initialize properly
I find this highly suspicious, especially if there are no compiler warnings.
> Stepping through in the debugger
Was that the exact code you compiled and debugged?
I can imagine a scenario where the compiler has optimised out some code because you do not actually use those variables, but has left enough information lying around for the debugger to think something is there when really there isn't.
Try this approach, which actually uses the variables. If all is well, it should print pairs of identical pointers.
> HPUX c programming with the cc compiler?Code:int some_var = 345;
/* same thing as globals */
/* this really tests the const-ness of the expressions */
struct { int x; char array[32]; } g_X = { 0 };
struct SomeStruct { char* p; } g_SSInstance = { g_X.array };
int main( ) {
struct { int x; char array[32]; } X = { 0 };
struct SomeStruct { char* p; } SSInstance = { X.array };
#ifdef __STDC__
printf( "Yes, Its ANSI-C\n" );
#endif
printf( "%p %p\n", g_SSInstance.p, g_X.array );
printf( "%p %p\n", SSInstance.p, X.array );
return 0;
}
I can't comment on HP, but my past experience with Sun's suggests that cc invokes the traditional (K&R) compiler, and the command to invoke an ANSI-C compiler is either different (eg. acc), or requires additional command line flags.
Does your compiler have the equivalent of the gcc '-S' option - which causes the compiler to output the actual assembler code it generated?
This is what I get from Borland 5.5, which I've always found to be a good c89 only compiler:Quote:
Originally posted by Salem
I'm reasonably sure that what you're trying to do is C89. I compiled it with "gcc -ansi -pedantic -Wall cpr-test.c", and gcc is pretty good at spotting non-standard things with those two flags.
K&R2 says:Code:Error E2063 junk1.c 7: Illegal initialization in function main
Not sure if this helps any...Quote:
A structure may be initialized by a list of constant member values;
>>So work with me here.
We are! :p
Salem, I can't compile your code, it still says illegal init, but only for the structs within main, the global is OK. I made the struct X in main static, and it compiled OK.
Salem:
The output to your test program was:
hux1:/usr/users/kludwig/ctestcode> cc -o ktest4 +DA2.0W ktest4.c
hux1:/usr/users/kludwig/ctestcode> ./ktest4
Yes, Its ANSI-C
800000010000008c 800000010000008c
ffffffffffffff64 800003ffff7f0684
hux1:/usr/users/kludwig/ctestcode>
So the global data initializes properly, the stack initialization fails at run time.
As you can see, there were no compiler warnings.
Salem,
When compiled as the following:
The output is:Code:int main( ) {
struct { int x; char array[32]; } X = { 0 };
struct SomeStruct { char* p; } SSInstance = { X.array };
#ifdef __STDC__
printf( "Yes, Its ANSI-C\n" );
#endif
printf( "%p %p\n", SSInstance.p, X.array );
return 0;
}
hux1:/usr/users/kludwig/ctestcode> cc -o ktest4 +DA2.0W ktest4.c
hux1:/usr/users/kludwig/ctestcode> ./ktest4
Yes, Its ANSI-C
800003ffff7f0684 800003ffff7f0684
hux1:/usr/users/kludwig/ctestcode>
So it is an ANSI-C compiler.
So there is nothing wrong with the code (OK, technically its not c89), but at least the compiler does not choke on it.
And it certainly seems capable of generating the right code when there are no globals around.
On the face of it, it looks like a compiler bug (brave words). Checking the produced assembler (see above) could show this to be the case (ie, the same code should not produce different assembly output).
It might be an idea to see if there are any recent patches for the compiler.
I imagine that your company is paying support $$$ for this compiler - if so, make them earn it a little.
My suggested workaround alternative would be to move all the global vars into globals.c, and create a globals.h to be included in the rest of the source files.