Bug help in AIX VisualAge C - Unix

This is a discussion on Bug help in AIX VisualAge C - Unix ; Hi, I met "Core" in my program. Help needed to review my source code. Detail environment: OS: AIX 5.3.0.0 (64bit) Complier: VisualAge C 6 -----example.c----------- #include struct Example { int length; int width; }; typedef struct Example *EXAMPLE; int main(int ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Bug help in AIX VisualAge C

  1. Bug help in AIX VisualAge C

    Hi, I met "Core" in my program. Help needed to review my source code.
    Detail environment:
    OS: AIX 5.3.0.0 (64bit)
    Complier: VisualAge C 6

    -----example.c-----------
    #include

    struct Example {
    int length;
    int width;
    };
    typedef struct Example *EXAMPLE;

    int
    main(int argc, char **argv)
    {
    EXAMPLE exp;

    exp = (EXAMPLE) malloc(sizeof(struct Example));

    printf("step 1\n");
    exp->length = 10;
    printf("step 2\n");

    exit(0);
    }
    -----------------------------

    when I compile the code with: "cc -q32 example.c -o example", I got
    the 32-bit mode object "example", and it runs normally with the
    output:
    step 1
    step 2
    but, with the 64-bit compile mode: "cc -q64 example.c -o example", the
    "example" will "core" at "exp->length = 10;", the output:
    step 1
    Segmentation fault(coredump)
    I took some time to debug, but got nothing. Thank you for your help.

  2. Re: Bug help in AIX VisualAge C

    fatfish writes:

    > Hi, I met "Core" in my program. Help needed to review my source code.
    > Detail environment:
    > OS: AIX 5.3.0.0 (64bit)
    > Complier: VisualAge C 6
    >
    > -----example.c-----------
    > #include
    >
    > struct Example {
    > int length;
    > int width;
    > };
    > typedef struct Example *EXAMPLE;
    >
    > int
    > main(int argc, char **argv)
    > {
    > EXAMPLE exp;
    >
    > exp = (EXAMPLE) malloc(sizeof(struct Example));
    >
    > printf("step 1\n");
    > exp->length = 10;
    > printf("step 2\n");
    >
    > exit(0);
    > }
    > -----------------------------
    >
    > when I compile the code with: "cc -q32 example.c -o example", I got
    > the 32-bit mode object "example", and it runs normally with the
    > output:
    > step 1
    > step 2
    > but, with the 64-bit compile mode: "cc -q64 example.c -o example", the
    > "example" will "core" at "exp->length = 10;", the output:
    > step 1
    > Segmentation fault(coredump)
    > I took some time to debug, but got nothing. Thank you for your help.


    A guess: there's no prototype for malloc in the scope (#include
    is missing) hence it's taken to mean `int malloc ();' and
    in 64 bit mode where (most likely) `sizeof (int) < sizeof (ptr)' the
    result (an int after promotion to pointer) is bogus. It's a good
    idea to compile things with warnings enabled.

    --
    mailto:av1474@comtv.ru

  3. Re: Bug help in AIX VisualAge C

    Thank you, the program runs ok with included.
    But why it's taken to mean `int malloc ();' instead of 'void
    *malloc();' ?

    On Mar 18, 3:55*am, m...@pulsesoft.com wrote:
    > fatfish writes:
    > > Hi, I met "Core" in my program. Help needed to review my source code.
    > > Detail environment:
    > > OS: AIX 5.3.0.0 (64bit)
    > > Complier: VisualAge C 6

    >
    > > -----example.c-----------
    > > #include

    >
    > > struct Example {
    > > * *int length;
    > > * *int width;
    > > };
    > > typedef struct Example *EXAMPLE;

    >
    > > int
    > > main(int argc, char **argv)
    > > {
    > > * *EXAMPLE exp;

    >
    > > * *exp = (EXAMPLE) malloc(sizeof(struct Example));

    >
    > > * *printf("step 1\n");
    > > * *exp->length = 10;
    > > * *printf("step 2\n");

    >
    > > * *exit(0);
    > > }
    > > -----------------------------

    >
    > > when I compile the code with: "cc -q32 example.c -o example", I got
    > > the 32-bit mode object "example", and it runs normally with the
    > > output:
    > > * *step 1
    > > * *step 2
    > > but, with the 64-bit compile mode: "cc -q64 example.c -o example", the
    > > "example" will "core" at "exp->length = 10;", the output:
    > > * *step 1
    > > * *Segmentation fault(coredump)
    > > I took some time to debug, but got nothing. Thank you for your help.

    >
    > A guess: there's no prototype for malloc in the scope (#include
    > is missing) hence it's taken to mean `int malloc ();' and
    > in 64 bit mode where (most likely) `sizeof (int) < sizeof (ptr)' the
    > result (an int after promotion to pointer) is bogus. It's a good
    > idea to compile things with warnings enabled.
    >
    > --
    > mailto:av1...@comtv.ru- Hide quoted text -
    >
    > - Show quoted text -



  4. Re: Bug help in AIX VisualAge C

    fatfish writes:

    > Thank you, the program runs ok with included.
    > But why it's taken to mean `int malloc ();' instead of 'void
    > *malloc();' ?


    Mainly because 3.3.2.2 of C90 standard says so.

    [..snip..]

    --
    mailto:av1474@comtv.ru

+ Reply to Thread