Thread: Is there an HPUX c newsgroup?

  1. #1
    Registered User
    Join Date
    Aug 2002
    Location
    Hermosa Beach, CA
    Posts
    446

    Is there an HPUX c newsgroup?

    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.
    The crows maintain that a single crow could destroy the heavens. Doubtless this is so. But it proves nothing against the heavens, for the heavens signify simply: the impossibility of crows.

  2. #2
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    There's comp.unix.programmer and comp.sys.hp.hpux

  3. #3
    Registered User quagsire's Avatar
    Join Date
    Jun 2002
    Posts
    60
    www.tek-tips.com

    Search for "hp-ux"

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231

    Re: Is there an HPUX c newsgroup?

    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 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.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Registered User
    Join Date
    Aug 2002
    Location
    Hermosa Beach, CA
    Posts
    446
    I run the following program:

    Code:
    int some_var = 345;
    
    int main()
    {
        struct { int x; char array[32]; } X = { 0 };
        struct SomeStruct { char* p; } SSInstance = { X.array };
    
        return 0;
    }
    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.

    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.
    The crows maintain that a single crow could destroy the heavens. Doubtless this is so. But it proves nothing against the heavens, for the heavens signify simply: the impossibility of crows.

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    My compiler won't let me initialise like that, I'd do it this way:
    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;
    }
    What you're doing is probably non-standard, I'll try to dig out some documentation later, unless someone beats me to it...
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  7. #7
    Registered User
    Join Date
    Aug 2002
    Location
    Hermosa Beach, CA
    Posts
    446
    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.
    The crows maintain that a single crow could destroy the heavens. Doubtless this is so. But it proves nothing against the heavens, for the heavens signify simply: the impossibility of crows.

  8. #8
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Yes, it's because it needs to be a const value.

    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;
    Why do you have to do that?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  9. #9
    Registered User
    Join Date
    Aug 2002
    Location
    Hermosa Beach, CA
    Posts
    446
    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.
    The crows maintain that a single crow could destroy the heavens. Doubtless this is so. But it proves nothing against the heavens, for the heavens signify simply: the impossibility of crows.

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.
    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;
    }
    > HPUX c programming with the cc compiler?
    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?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  11. #11
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    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.
    This is what I get from Borland 5.5, which I've always found to be a good c89 only compiler:
    Code:
    Error E2063 junk1.c 7: Illegal initialization in function main
    K&R2 says:
    A structure may be initialized by a list of constant member values;
    Not sure if this helps any...

    >>So work with me here.
    We are!
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  12. #12
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    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.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  13. #13
    Registered User
    Join Date
    Aug 2002
    Location
    Hermosa Beach, CA
    Posts
    446
    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.
    The crows maintain that a single crow could destroy the heavens. Doubtless this is so. But it proves nothing against the heavens, for the heavens signify simply: the impossibility of crows.

  14. #14
    Registered User
    Join Date
    Aug 2002
    Location
    Hermosa Beach, CA
    Posts
    446
    Salem,

    When compiled as the following:

    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;
    
    }
    The output is:

    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>
    The crows maintain that a single crow could destroy the heavens. Doubtless this is so. But it proves nothing against the heavens, for the heavens signify simply: the impossibility of crows.

  15. #15
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. HPUX sockets vs Linux?
    By cpjust in forum Linux Programming
    Replies: 4
    Last Post: 12-06-2007, 02:51 PM
  2. HPUX stack trace
    By IfYouSaySo in forum C Programming
    Replies: 0
    Last Post: 10-15-2002, 07:36 PM
  3. Establish newsgroup..
    By Nutshell in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 04-19-2002, 10:06 PM